【SDK fix】iOS 8下将UIButton放置于tabbar位置没法响应event

本blog除部分译文外,全部内容均为原创,若有雷同,算我抄你:-)git

问题描述

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

objcdetailVC.hidesBottomBarWhenPushed = YES;

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

触发环境

iOS 7或以上,真机调试。ide

分析过程

先查看HitTest的结果,button实例被正确地返回了。这说明button并无被透明的view所遮盖。
接着,override button的touchesXXX方法。当按下button的左下角时,touchesBegan等4个方法彻底没有被调用到。参考下图
图片描述
应该存在一个gesture recognizer,而且delaysTouchesBegan设置为YES。ui

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.this

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

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

获得结果
图片描述
那么答案就很明显了。调试

解决方案

objcself.navigationController.interactivePopGestureRecognizer.delaysTouchesBegan = NO;

Demo

Button touch down bug fixcode

参考资料

Placing a UIButton in the same space as UITabBar (When hidden)orm

相关文章
相关标签/搜索