将触摸事件传递到iOS状态栏 [英] Passing touch events to iOS status bar

查看:98
本文介绍了将触摸事件传递到iOS状态栏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个UIWindow windowLevel设置为UIWindowLevelStatusBar + 1。此窗口具有阻止状态栏的单个半透明视图。我需要有时将触摸事件从视图传递到状态栏。任何想法?

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 events from the view on to the status bar. Any ideas?

推荐答案

所以,似乎可以做一个自定义子类UIWindow覆盖 hitTest: withEvent:手动检测子视图中的触摸,并始终返回nil。

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

状态栏识别所有触摸,因此滚动到顶部,返回到通话,VoiceOver等。我还是得到拦截在状态栏上的水龙头。

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.

我刚刚黑了这个。

编辑 - 4月7日:

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

这篇关于将触摸事件传递到iOS状态栏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆