I'm trying to detect any touch on the iPhone's UIStatusBar
but its not working. I've tri开发者_JAVA技巧ed subclassing UIApplication
and UIWindow
to access it but still nothing.
Based on Tom's answer, I wrote the code. It works well.
- (void)viewDidLoad {
[super viewDidLoad];
// required
UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:CGRectZero];
scrollView.delegate = self;
scrollView.contentSize = CGSizeMake(0.0f,1.0f);
[scrollView setContentOffset:CGPointMake(0.0f,1.0f) animated:NO];
// optional
scrollView.scrollsToTop = YES; // default is YES.
[self.view addSubview:scrollView];
}
- (BOOL)scrollViewShouldScrollToTop:(UIScrollView *)scrollView {
NSLog(@"Detect status bar is touched.");
/* Your own code. */
return 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 return NO
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.
精彩评论