TopmostView 1.0.0

TopmostView 1.0.0

TestsTested
LangLanguage Obj-CObjective C
License MIT
ReleasedLast Release Nov 2017

Maintained by HarrisonXi.



  • By
  • HarrisonXi

TopmostView

Get topmost view for UIWindow. The topmost view can rotate correctly with devices. The test project contains a simple toast implemention. Supports iOS 7-11.

Get topmost view for the application window:

// The application window is [UIApplicationDelegate window].
[TopmostView viewForApplicationWindow]

Get topmost view for the keyboard window:

[TopmostView viewForKeyboardWindow]

Get topmost view for a new window over status bar:

[TopmostView viewForStatusBarWindow]

Get topmost view for a new window over alert view:

// It is for iOS 7/8, UIAlertView cteate a new window which level = UIWindowLevelAlert.
// For iOS >= 9, UIAlertController does not create a new window.
[TopmostView viewForAlertWindow]

Get topmost view for specified window:

[TopmostView viewForWindow:window]

中文介绍

获得 UIWindow 里最顶层的 view。这个最顶层的 view 可以随着设备正常的旋转。另外测试工程里包含一个简单的 toast 实现。支持 iOS 7-11。

获得应用程序 window 里最顶层的 view:

// 应用程序 window 的值是 [UIApplicationDelegate window]。
[TopmostView viewForApplicationWindow]

获得键盘 window 里最顶层的 view:

[TopmostView viewForKeyboardWindow]

获得一个覆盖在状态条之上的新 window 里最顶层的 view:

[TopmostView viewForStatusBarWindow]

获得一个覆盖在 Alert 弹窗之上的新 window 里最顶层的 view:

// 这是用在 iOS 7/8 上的,UIAlertView 会创建一个 level 为 UIWindowLevelAlert 的 window。
// 在 iOS >= 9 的设备上,UIAlertController 是不会创建新 window 的。
[TopmostView viewForAlertWindow]

获得指定 window 里最顶层的 view:

[TopmostView viewForWindow:window]

实现细节逻辑相关blog:iOS系统的键盘windowiOS系统window的旋转及自定义window的问题