在以下屏幕截图中,如果我从“可用信息亭”单击“v”,将启动后退按钮...(不是第二个“a”)的操作。UINavigationItem后退按钮触摸区域太大
我不明白为什么,我没有什么特别的在我的代码(这是由导航控制器处理的默认后退按钮)。 我也有与我做的另一个应用程序相同的错误,但我从来没有注意到这在其他应用程序。
任何想法?
谢谢。
在以下屏幕截图中,如果我从“可用信息亭”单击“v”,将启动后退按钮...(不是第二个“a”)的操作。UINavigationItem后退按钮触摸区域太大
我不明白为什么,我没有什么特别的在我的代码(这是由导航控制器处理的默认后退按钮)。 我也有与我做的另一个应用程序相同的错误,但我从来没有注意到这在其他应用程序。
任何想法?
谢谢。
这不是一个错误,它在Apple应用程序中甚至在某些(许多/全部?)按钮上也是如此。这是按钮上触摸事件的行为:触摸区域大于按钮边界。
我需要做同样的事情,所以我最终调用了UINavigationBar touchesBegan:withEvent方法,并在调用原始方法之前检查触摸的y坐标。
这意味着当触摸距离我在导航下使用的按钮太近时,我可以取消它。
例如:后退按钮几乎总是捕获的触摸事件,而不是“第一”按钮
这里是我的类别:
@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:));
我不知道苹果是否可以这样做,它可能会侵犯他们的用户界面指南,如果我将应用程序提交给应用程序商店后,我会尝试更新帖子。
我现在有同样的问题,你找到解决方案吗? – 2011-04-07 09:31:22
不好意思...我在许多应用程序中发现了这个错误...:o – 2011-04-08 19:52:53