Object -C 版本:
1
2
3
4
5
6
7
8
9
|
- (UIViewController *)appRootViewController
{
UIViewController *appRootVC = [UIApplication sharedApplication].keyWindow.rootViewController;
UIViewController *topVC = appRootVC;
while
(topVC.presentedViewController) {
topVC = topVC.presentedViewController;
}
return
topVC;
}
|
Swift版本:
1
2
3
4
5
6
7
|
func AppRootViewController() -> UIViewController? {
var topVC = UIApplication.sharedApplication().keyWindow?.rootViewController
while
topVC?.presentedViewController != nil {
topVC = topVC?.presentedViewController
}
return
topVC?
}
|