Skip to content

Instantly share code, notes, and snippets.

@ripperhe
Last active September 18, 2018 06:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ripperhe/80075f8b3b544b0f552e69bb1fb9dc20 to your computer and use it in GitHub Desktop.
Save ripperhe/80075f8b3b544b0f552e69bb1fb9dc20 to your computer and use it in GitHub Desktop.
iOS APP 中查找显示在最上面的、全屏的、可见的 window(大部分情况都适用)
- (UIWindow *)topFullScreenVisibleWindow
{
NSArray *windows = [UIApplication sharedApplication].windows;
for (UIWindow *window in windows.reverseObjectEnumerator) {
if (window.hidden == YES || window.opaque == NO) {
continue;
}
if (CGRectEqualToRect(window.bounds, [UIScreen mainScreen].bounds) == NO) {
continue;
}
return window;
}
if ([UIApplication sharedApplication].keyWindow) {
return [UIApplication sharedApplication].keyWindow;
}
if ([[UIApplication sharedApplication].delegate respondsToSelector:@selector(window)]) {
return [UIApplication sharedApplication].delegate.window;
}
return nil;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment