如何检测 UIStatusBar/iPhone 上的触摸
我正在尝试检测 iPhone 的 UIStatusBar
上的任何触摸,但它不起作用。我已经尝试子类化 UIApplication
和 UIWindow
来访问它,但仍然没有任何结果。
I'm trying to detect any touch on the iPhone's UIStatusBar
but its not working. I've tried subclassing UIApplication
and UIWindow
to access it but still nothing.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
根据汤姆的回答,我编写了代码。效果很好。
Based on Tom's answer, I wrote the code. It works well.
您的响应者链中需要有一个 UIScrollView,并且它需要有一个委托集。然后,您可以在委托中重写
scrollViewShouldScrollToTop:
,当用户点击状态栏时将调用该委托。如果您不希望将滚动视图滚动回顶部的默认行为,请务必返回NO
。You need to have a UIScrollView in your responder chain, and it needs to have a delegate set. You can then override
scrollViewShouldScrollToTop:
in the delegate, which will be called when the user taps on the status bar. Be sure to returnNO
if you don't want the default behavior of scrolling the scroll view back to the top.你不能。状态栏由应用程序持有。您只能打开和关闭它。
更重要的是,任何对状态栏的摆弄都可能会让你的应用程序被苹果拒绝,因为它可能会干扰硬件的操作,例如伪装或隐藏低电量。
如果您需要全屏触摸来查看视图,您应该隐藏状态栏。
You can't. The status bar is held by the application. You can only turn it on and off.
More importantly, any fiddling with the status bar is likely to get your app rejected by Apple because it could interfere with the operation of the hardware e.g. disguising or hiding a low battery.
If you need full screen touches for your views you should just hide the status bar.