错误的UISearchBar接触区域

时间:2015-12-07 16:13:52

标签: ios objective-c uinavigationcontroller uisearchbar uistatusbar

摘要

在没有它的情况下从视图控制器推送带有状态栏的视图控制器后,我的UISearchBar触摸区域出错了。

解释

我在UINavigationController内有两个视图控制器A和B.隐藏状态栏,其中包含以下代码:

- (BOOL)prefersStatusBarHidden {
    return YES;
}

B UISearchBar标题视图中有UINavigationController。在此视图中,状态栏已启用:

- (UIStatusBarStyle)preferredStatusBarStyle {
    return UIStatusBarStyleDefault;
}

从A:

推B后似乎没有错

enter image description here enter image description here

但是当我尝试按下测试按钮或状态栏时,我的触摸识别错误:

enter image description here

当我按下导航栏下的红色区域时,搜索栏和后退按钮变为活动状态。

视频:https://www.youtube.com/watch?v=Jw4kDOFBCIg

小样本项目:https://github.com/leo150/SearchBarTest

有什么想法吗?感谢

2 个答案:

答案 0 :(得分:1)

这实际上是苹果公司实施的一个错误或特征。导航栏下方的按钮始终存在问题。

Apple可能已经这样做了,因此更容易点击更突出的UI部分(导航栏)。

答案 1 :(得分:1)

Like Alistra said it's an Apple's implementation for a better UX.

Here is a related thread with some work around: Why does UINavigationBar steal touch events?

And the official answer of an Apple's engineer:

I recommend that you avoid having touch-sensitive UI in such close proximity to the nav bar or toolbar. These areas are typically known as "slop factors" making it easier for users to perform touch events on buttons without the difficulty of performing precision touches. This is also the case for UIButtons for example.

But if you want to capture the touch event before the navigation bar or toolbar receives it, you can subclass UIWindow and override: -(void)sendEvent:(UIEvent *)event;