#pragma mark - 获取当前最顶层的ViewController
- (UIViewController*)topVC:(UIViewController*)VC {
if([VC isKindOfClass:[UINavigationControllerclass]]) {
return[selftopVC:[(UINavigationController*)VC topViewController]];
}
if([VC isKindOfClass:[UITabBarControllerclass]]) {
return[selftopVC:[(UITabBarController*)VC selectedViewController]];
}
returnVC;
}
- (UIViewController*)topViewController {
UIViewController*vc = [selftopVC:[UIApplicationsharedApplication].keyWindow.rootViewController];
while(vc.presentedViewController) {
vc = [selftopVC:vc];
}
returnvc;
}