iOS獲取window

z小志發表於2018-01-23
  • (UIWindow *)lastWindow { NSEnumerator *frontToBackWindows = [UIApplication.sharedApplication.windows reverseObjectEnumerator]; for (UIWindow *window in frontToBackWindows) { BOOL windowOnMainScreen = window.screen == UIScreen.mainScreen; BOOL windowIsVisible = !window.hidden && window.alpha > 0; BOOL windowLevelSupported = (window.windowLevel >= UIWindowLevelNormal && window.windowLevel <= UIWindowLevelNormal); BOOL windowKeyWindow = window.isKeyWindow;

      if(windowOnMainScreen && windowIsVisible && windowLevelSupported && windowKeyWindow) {
          return window;
      }
    複製程式碼

    }

    return nil; }

相關文章