iOS13: how to detect a status bar click event?

后端 未结 2 1915
渐次进展
渐次进展 2021-02-01 09:00

In my appDelegate, I override touchesBegan to detect when the status bar is clicked:

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)even         


        
相关标签:
2条回答
  • 2021-02-01 09:52

    After some research, I found that the status bar is no longer part of the application on iOS13, it’s part of the system UI (“springboard”). You need to access it via UIStatusBarManager

    So this no longer works:

    CGRect statusBarFrame = [UIApplication sharedApplication].statusBarFrame;
    

    In iOS 13, you need to get the StatusBar frame like this:

    UIStatusBarManager *manager = [UIApplication sharedApplication].keyWindow.windowScene.statusBarManager;
    CGRect statusBarFrame = manager.statusBarFrame;
    
    0 讨论(0)
  • 2021-02-01 09:55

    In iOS 13, StatusBar Event was managed by UIStatusBarManager, these methods will be called when click the StatusBar:

    -[UIStatusBarManager _handleScrollToTopAtXPosition:]
    -[UIStatusBarManager handleTapAction:]
    

    So, you can hook -[UIStatusBarManager handleTapAction:] to detecte StatusBar click event

    0 讨论(0)
提交回复
热议问题