subView - >
@property (nonatomic, copy) void(^didTapBlankBlock)(void);
具体实现 重写hitTest方法。
- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event {
UIView *view = [super hitTest:point withEvent:event];
if (view == self) {
view = nil;
if (self.didTapBlankBlock) {
self.didTapBlankBlock();
}
}
return view;
}
创建类似VC
- (void)loadView {
self.view = [[ alloc] initWithFrame:UIApplication.sharedApplication.keyWindow.bounds];
}
识别当前最顶层VC
UIViewController *rootVC = [[[[UIApplication sharedApplication] delegate] window] rootViewController];
while (resultVC.presentedViewController) {
resultVC = [self fetch_topViewController:resultVC.presentedViewController];
}
return resultVC;
+ (UIViewController *)fetch_topViewController:(UIViewController *)vc {
if ([vc isKindOfClass:[UINavigationController class]]) {
return [self fetch_topViewController:[(UINavigationController *)vc topViewController]];
} else if ([vc isKindOfClass:[UITabBarController class]]) {
return [self fetch_topViewController:[(UITabBarController *)vc selectedViewController]];
} else {
return vc;
}
return nil;
}
网友评论