gpt4 book ai didi

ios - 错误的 UISearchBar 触摸区域

转载 作者:搜寻专家 更新时间:2023-10-30 20:15:16 24 4
gpt4 key购买 nike

总结

从不带状态栏的 View Controller 推送带状态栏的 View Controller 后,UISearchBar 触摸区域出现错误。

解释

我在 UINavigationController 中有两个 View Controller A 和 B。使用以下代码隐藏状态栏:

- (BOOL)prefersStatusBarHidden {
return YES;
}

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

- (UIStatusBarStyle)preferredStatusBarStyle {
return UIStatusBarStyleDefault;
}

从A push 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

有什么想法吗?谢谢

最佳答案

正如 Alistra 所说,这是 Apple 为实现更好的用户体验而实现的。

这是一个相关的线程,有一些解决方法: Why does UINavigationBar steal touch events?

还有 official answer苹果工程师的:

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;

关于ios - 错误的 UISearchBar 触摸区域,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34138138/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com