32 lines
1.0 KiB
Dart
32 lines
1.0 KiB
Dart
|
//
|
||
|
// MOPTools.m
|
||
|
// mop
|
||
|
//
|
||
|
// Created by 杨涛 on 2020/2/27.
|
||
|
//
|
||
|
|
||
|
#import "MOPTools.h"
|
||
|
|
||
|
@implementation MOPTools
|
||
|
+ (UIViewController *)topViewController{
|
||
|
return [self topViewController:[UIApplication sharedApplication].keyWindow.rootViewController];
|
||
|
}
|
||
|
|
||
|
+ (UIViewController *)topViewController:(UIViewController *)rootViewController
|
||
|
{
|
||
|
if (rootViewController.presentedViewController == nil) {
|
||
|
return rootViewController;
|
||
|
}
|
||
|
|
||
|
if ([rootViewController.presentedViewController isMemberOfClass:[UINavigationController class]]) {
|
||
|
UINavigationController *navigationController = (UINavigationController *)rootViewController.presentedViewController;
|
||
|
UIViewController *lastViewController = [[navigationController viewControllers] lastObject];
|
||
|
return [self topViewController:lastViewController];
|
||
|
}
|
||
|
|
||
|
UIViewController *presentedViewController = (UIViewController *)rootViewController.presentedViewController;
|
||
|
return [self topViewController:presentedViewController];
|
||
|
}
|
||
|
|
||
|
@end
|