简体   繁体   中英

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.

I expected to find a notification that I could listen to and then use tableview:scrollToRowAtIndexPath: for the scroll, but can find none.

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. Also, I have one UIScrollView, but also UITextView, so I wonder if that is eating it.

I will see what I can do with scrollsToTop.

This article on cocoawithlove.com is exactly what you want.

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

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

This might be major overkill, but you could write your own status bar.

You can hide the actual status bar by setting the "Status bar is initially hidden" to YES in your application plist. 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.

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]; (then use NSDateFormatter to format).

Getting the signal strength is a little iffy but can be roughly estimated with a certain degree of ingenuity.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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