1

我在 ui 控制器上创建了一个“经典”类别,以我的方式呈现另一个控制器。

@interface UIViewController (QZPopup)
- (void)presentPopupViewController:(UIViewController *)viewControllerToPresent animated:(BOOL)flag completion:(void (^)(void))completion;
- (void)dismissPopupViewControllerAnimated:(BOOL)flag completion:(void (^)(void))completion;
@end

该类别增加了:

  • 调用控制器视图顶部的模糊视图
  • 所有屏幕顶部的隐形视图。这个不可见的视图必须捕获触摸事件以关闭弹出窗口,并且在关闭弹出窗口后,我还想传输这个事件来做任何需要的事情。

对于我的使用,我UIController嵌入了一个UINavigationBarController. 我想让导航栏下方的部分模糊并且导航栏可见。对模糊视图的触摸只是关闭,而对导航栏的触摸必须关闭并执行导航栏中触摸项目所需的任何操作。

视觉在我这边还可以,但我无法通过事件并到达导航栏。目前我已经分类UIView如下QZPopupDismiss

@implementation QZPopupDismiss {
    touchCallback _touchCompletion;
}

- (instancetype)initWithFrame:(CGRect)frame andTouchCompletion:(touchCallback)completion {
    if (self = [self initWithFrame:frame]) {
        _touchCompletion = completion;
        self.userInteractionEnabled = YES;
    }
    return self;
}

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {

    // first do the touch completion
    _touchCompletion();

    // pass the event to the view hierarchy
    [super touchesEnded:touches withEvent:event];
}
@end

但事实是,在 中touchsEndedsuper没有到达导航栏。如何将我的事件传递给整个视图层次结构以到达导航栏项目?

4

0 回答 0