Search code examples
iosiphonexcodeuiwindowuiapplication

How do I detect touches on UIStatusBar/iPhone


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.


Solution

  • 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;
    }