mop-flutter-sdk/ios/Classes/Utils/MOPTools.m

32 lines
1.0 KiB
Matlab
Raw Normal View History

2020-02-27 17:21:45 +08:00
//
// 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