subView - >
@property (nonatomic, copy) void(^didTapBlankBlock)(void);
具體實(shí)現(xiàn) 重寫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;
}
創(chuàng)建類似VC
- (void)loadView {
self.view = [[ alloc] initWithFrame:UIApplication.sharedApplication.keyWindow.bounds];
}
識(shí)別當(dāng)前最頂層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;
}