Ich musste das gleiche tun und so endete ich swizzling die UINavigationBar touchesBegan: withEvent Methode und Überprüfung der y-Koordinate der Berührung vor dem Aufruf der ursprünglichen Methode.
Dies bedeutet, dass, wenn die Berührung zu nahe an einer Taste war, die ich unter der Navigation verwendete, ich es abbrechen konnte.
Ex: Die Zurück-Taste fast immer das Berührungsereignis statt der "Ersten" Button ist gefangen
Hier meine Kategorie:
@implementation UINavigationBar (UINavigationBarCategory)
- (void)sTouchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
float maxY = 0;
for (UITouch *touch in touches) {
float touchY = [touch locationInView:self].y;
if ([touch locationInView:self].y > maxY) maxY = touchY;
}
NSLog(@"swizzlelichious bar touchY %f", maxY);
if (maxY < 35)
[self sTouchesEnded:touches withEvent:event];
else
[self touchesCancelled:touches withEvent:event];
}
- (void)sTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
float maxY = 0;
for (UITouch *touch in touches) {
float touchY = [touch locationInView:self].y;
if ([touch locationInView:self].y > maxY) maxY = touchY;
}
NSLog(@"swizzlelichious bar touchY %f", maxY);
if (maxY < 35)
[self sTouchesBegan:touches withEvent:event];
else
[self touchesCancelled:touches withEvent:event];
}
Die swizzle Implementierung von Mike Ash von CocoaDev
void Swizzle(Class c, SEL orig, SEL new)
{
Method origMethod = class_getInstanceMethod(c, orig);
Method newMethod = class_getInstanceMethod(c, new);
if(class_addMethod(c, orig, method_getImplementation(newMethod), method_getTypeEncoding(newMethod)))
class_replaceMethod(c, new, method_getImplementation(origMethod), method_getTypeEncoding(origMethod));
else
method_exchangeImplementations(origMethod, newMethod);
}
Und die Funktion ruft die Swizzle-Funktion
Ich weiß nicht, ob Apple damit einverstanden ist, es könnte verletzen ihre UI-Richtlinien, ich werde versuchen, den Beitrag zu aktualisieren, wenn ich die App an den App Store senden.
Ich habe das gleiche Problem jetzt, haben Sie eine Lösung gefunden? –
Nein sorry ... Ich habe diesen Fehler in vielen Apps gefunden ...: o –