简体   繁体   English

如何在iPhone状态栏中检测到触摸?

[英]How do I detect a touch in the iPhone status bar?

I have a UITableview that I would like to scroll to the top when the status bar is touched. 我有一个UITableview,当触摸状态栏时,我想滚动到顶部。

I expected to find a notification that I could listen to and then use tableview:scrollToRowAtIndexPath: for the scroll, but can find none. 我希望找到一个可以听的通知,然后将tableview:scrollToRowAtIndexPath:用于滚动,但找不到。

Is there a way to do this? 有没有办法做到这一点?

[Update] [更新]

Finding some more on the net, I am suspicious that this is the simulator biting me. 在网上找到更多信息,我怀疑这是模拟器在咬我。 My UIScrollView is failing to scroll to the top in the simulator, but I have not tried on hardware. 我的UIScrollView无法滚动到模拟器的顶部,但是我没有在硬件上尝试过。 Also, I have one UIScrollView, but also UITextView, so I wonder if that is eating it. 另外,我有一个UIScrollView,还有UITextView,所以我想知道是否在吃它。

I will see what I can do with scrollsToTop. 我将看到我可以使用scrollsToTop做什么。

This article on cocoawithlove.com is exactly what you want. 您真正想要的是cocoawithlove.com上的这篇文章

From that article: 从那篇文章:

"The trickiest part of the sample application is detecting a touch in the status bar. “示例应用程序最棘手的部分是检测状态栏中的触摸。

By implementing a custom setContentOffset:animated: method on a UITableView and setting a breakpoint in that method, you can see in the debugger stack that the UIApplication sendEvent: method is invoked for status bar touches, so that's where we'll begin." 通过在UITableView上实现自定义setContentOffset:animated:方法并在该方法中设置断点,您可以在调试器堆栈中看到为状态栏触摸而调用了UIApplication sendEvent:方法,因此我们将从这里开始。”

除非将scrollsToTop属性设置为NO,否则它应该是自动发生的。

This might be major overkill, but you could write your own status bar. 这可能是主要的矫over过正,但是您可以编写自己的状态栏。

You can hide the actual status bar by setting the "Status bar is initially hidden" to YES in your application plist. 您可以通过在应用程序plist中将“状态栏最初处于隐藏状态”设置为YES来隐藏实际状态栏。 Then create your own custom status bar view at the top of the view with height 20px that is either a UIButton or simply a UIView with a UITapGestureRecognizer. 然后在视图顶部以20px的高度创建自己的自定义状态栏视图,该视图可以是UIButton或只是具有UITapGestureRecognizer的UIView。

You can detect battery level/state (charge and plugged-in or not) with: 您可以使用以下方法检测电池电量/状态(是否已充电和未插入):

UIDevice *myDevice = [UIDevice currentDevice];
[myDevice setBatteryMonitoringEnabled:YES];

float batteryLevel = [myDevice batteryLevel];
UIDeviceBatteryState batteryState = [myDevice batteryState];

You can get the time with [NSDate date]; 您可以使用[NSDate date]获取时间; (then use NSDateFormatter to format). (然后使用NSDateFormatter进行格式化)。

Getting the signal strength is a little iffy but can be roughly estimated with a certain degree of ingenuity. 获得信号强度有些困难,但可以通过一定程度的独创性粗略估算。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM