2010-10-12 55 views
5

在以下屏幕截圖中,如果我從「可用信息亭」單擊「v」,將啓動後退按鈕...(不是第二個「a」)的操作。UINavigationItem後退按鈕觸摸區域太大

alt text

我不明白爲什麼,我沒有什麼特別的在我的代碼(這是由導航控制器處理的默認後退按鈕)。 我也有與我做的另一個應用程序相同的錯誤,但我從來沒有注意到這在其他應用程序。

任何想法?

謝謝。

+0

我現在有同樣的問題,你找到解決方案嗎? – 2011-04-07 09:31:22

+0

不好意思...我在許多應用程序中發現了這個錯誤...:o – 2011-04-08 19:52:53

回答

8

這不是一個錯誤,它在Apple應用程序中甚至在某些(許多/全部?)按鈕上也是如此。這是按鈕上觸摸事件的行爲:觸摸區域大於按鈕邊界。

1

我需要做同樣的事情,所以我最終調用了UINavigationBar touchesBegan:withEvent方法,並在調用原始方法之前檢查觸摸的y座標。
這意味着當觸摸距離我在導航下使用的按鈕太近時,我可以取消它。

例如:後退按鈕幾乎總是捕獲的觸摸事件,而不是「第一」按鈕 enter image description here

這裏是我的類別:

@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]; 
} 

的調配由Mike灰從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); 
} 

而函數調用swizzle函數

Swizzle([UINavigationBar class], @selector(touchesEnded:withEvent:), @selector(sTouchesEnded:withEvent:)); 
Swizzle([UINavigationBar class], @selector(touchesBegan:withEvent:), @selector(sTouchesBegan:withEvent:)); 

我不知道蘋果是否可以這樣做,它可能會侵犯他們的用戶界面指南,如果我將應用程序提交給應用程序商店後,我會嘗試更新帖子。

相關問題