NSFish / buttonTouchEventTest

修复Button touchDown bug

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

##问题描述 问题来自于iOS UIButton 的 touchDown 事件这篇帖子。简单地说,在设置

detailVC.hidesBottomBarWhenPushed = YES;

之后,放一个view在tabbar原来的位置上,再在view上添加一个button,像这样 图片描述 为button添加touchDown action,当按住button的左下角区域时,action没有被触发。

##触发环境 iOS 7或以上,真机调试。 ##分析过程 先查看HitTest的结果,button实例被正确地返回了。这说明button并没有被透明的view所遮盖。 接着,override button的touchesXXX方法。当按下button的左下角时,touchesBegan等4个方法完全没有被调用到。参考下图 图片描述 应该存在一个gesture recognizer,并且delaysTouchesBegan设置为YES。

delaysTouchesBegan (default of NO)—Normally, the window sends touch objects in the Began and Moved phases to the view and the gesture recognizer. Setting delaysTouchesBegan to YES prevents the window from delivering touch objects in the Began phase to the view. This ensures that when a gesture recognizer recognizes its gesture, no part of the touch event was delivered to the attached view. Be cautious when setting this property because it can make your interface feel unresponsive.

考虑当前场景,应该是滑动返回手势捣的鬼。稍微验证一下

- (void)viewDidLoad
{
    //Other codes here
    NSLog(@"%d", self.navigationController.interactivePopGestureRecognizer.delaysTouchesBegan);
}

得到结果 图片描述 那么答案就很明显了。 ##解决方案

self.navigationController.interactivePopGestureRecognizer.delaysTouchesBegan = NO;

##参考资料 Placing a UIButton in the same space as UITabBar (When hidden)

About

修复Button touchDown bug


Languages

Language:Objective-C 100.0%