获取工程中window上面的RootViewController keyWindow是,在windows数组中最近时间调用makeKeyAndVisible方法的属性。windows
AppDelegate *app =(AppDelegate *) [UIApplication sharedApplication].delegate;
UIViewController *rootViewController1 = appdelegate.window.rootViewController;
复制代码
AppDelegate *appdelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
if ([appdelegate.window.rootViewController isKindOfClass:["xxxrootVC" class]] == YES) {
// 这样更保险
}
复制代码
UIAlertController或UIAlertView或UIActionSheet弹出后,keyWindow就会变成UIAlertControllerShimPresenterWindow这个类数组
UIWindow *window = [UIApplication sharedApplication].keyWindow;
UIViewController *rootViewController2 = window.rootViewController;
复制代码
alertView的出现是由于,生成了一个新的window,加在了界面上面。 这个时候获取到的keyWindow就是UIAlertControllerShimPresenterWindow。bash