Passing touch events to iOS status bar

后端 未结 3 1663
误落风尘
误落风尘 2021-01-03 12:38

I have a UIWindow with windowLevel set to UIWindowLevelStatusBar+1. This window has a single semi-transparent view that blocks the status bar. I need to sometimes pass touch

3条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-03 13:20

    So, it seems to be doable with a custom subclass of UIWindow overriding hitTest:withEvent: that manually detects a touch in the subview, and always returns nil.

    - (UIView*)hitTest:(CGPoint)point withEvent:(UIEvent *)event {
        if ([event type]==UIEventTypeTouches) {
            UIView *v=[super hitTest:point withEvent:event];
            if (customSubViewthatCoversStatusBarOnly==v) 
                //doLotsOfCoolStuff
        }
    
        return nil;
    }
    

    Status bar recognizes all touches, so there is no breakage with scroll-to-top, return to call, VoiceOver, etc.. And I still get to intercept taps on statusbar.

    I hacked this up just now. I will probably upload an update to App Store later this week with a more mature version of this, will see how much complaining Apple will do.

    EDIT - 7th April:
    Was approved by Apple. Works flawlessly.

提交回复
热议问题