Ann*_*son 33
好的,这就是我做的:我在前窗口创建了两个视图.第一个视图涵盖了我想要触及的区域; 第二,我希望触摸通过.我对UIWindow进行了分类并覆盖了hitTest:withEvent方法,如下所示:
- (UIView *) hitTest:(CGPoint)point withEvent:(UIEvent *)event {
// See if the hit is anywhere in our view hierarchy
UIView *hitTestResult = [super hitTest:point withEvent:event];
// ABKSlideupHostOverlay view covers the pass-through touch area. It's recognized
// by class, here, because the window doesn't have a pointer to the actual view object.
if ([hitTestResult isKindOfClass:[ABKSlideupHostOverlayView class]]) {
// Returning nil means this window's hierachy doesn't handle this event. Consequently,
// the event will be passed to the host window.
return nil;
}
return hitTestResult;
}
Run Code Online (Sandbox Code Playgroud)
在创建前窗的类中,我使用手势识别器来捕捉第一个视图的触摸.
2017年代码相同:
class PassView: UIView {}
class UIHigherWindow: UIWindow {
override func hitTest(_ point: CGPoint, with event: UIEvent?) -> UIView? {
let hitView = super.hitTest(point, with: event)
if hitView!.isKind(of: PassView.self) {
return nil
}
return hitView
}
}
Run Code Online (Sandbox Code Playgroud)
你的"超级"窗口将是一些视图控制器,UberVc.
只需让UberVc的主视图(也就是说,背景.view)成为PassView.
然后在UberVc上添加说按钮等.
上面的代码会导致UberVc按钮上的任何点击,以及任何不在按钮上的点击(即,在"背景"上)点击进入常规窗口/ VC.
| 归档时间: |
|
| 查看次数: |
5016 次 |
| 最近记录: |