方式一:(此方式不严谨,最好用方式二)
[[UIApplication sharedApplication].windows lastObject];
方式二:
+ (UIWindow *)lastWindow
{
NSArray *windows = [UIApplication sharedApplication].windows;
for(UIWindow *window in [windows reverseObjectEnumerator]) {
if ([window isKindOfClass:[UIWindow class]] &&
CGRectEqualToRect(window.bounds, [UIScreen mainScreen].bounds))
return window;
}
return [UIApplication sharedApplication].keyWindow;
}