这是一个用 Objective-C 编写的简单窗口展示管理器,它利用了 UIWindow
。
UIWindow
可以将任何 UIViewController
子类作为根控制器。通常,一个完整的应用都会被限制在单个 UIWindow
中。此管理器允许您创建许多具有不同 z 位置的 TTWindow
对象,以便创建独特的用户界面!
UIStatusBar
之上显示视图!我在 Swift 存在之前就写了 TTWindowManager。我没有将其转换为 Swift,但现在我已经完全拥抱了 Swift,因此我将仅展示 Swift 实现。
TTWindowManager/TTWindowManager
文件夹拖拽到您的项目中。#import TTWindowManager.h
添加到项目的 Bridge Header 中,并开始编写代码!在 AppDelegate 中用 TTWindow
覆盖主 UIWindow
,以充分利用堆栈。
class AppDelegate: UIResponder, UIApplicationDelegate {
// var window: UIWindow?
//Replace default with TTWindow override
var window : UIWindow? = {
let window = TTWindow()
return window
} ()
func application(application: UIApplication, willFinishLaunchingWithOptions launchOptions: [NSObject : AnyObject]?) -> Bool {
//Important to ensure the window is properly sized
self.window?.frame = UIScreen.mainScreen().bounds
return true
}
}
向 AppDelegate 中的 didFinishLaunchingWithOptions
添加摇晃手势回调以显示调试控制台或应用特定的其他内容
如果覆盖了默认的 UIWindow,请将其添加到 AppDelegate 的
didFinishLaunchingWithOptions
(self.window as! TTWindow).shakeGestureCallback = { () -> Void in
//Display something on shake
println("Shake!")
}
快速使用动画和特定窗口级别显示新的 TTWindow
TTWindowManager.sharedInstance().presentViewController(viewController, atWindowPosition: .Modal, withAnimation: .Modal) { (success) -> Void in
}
TTWindowPosition
决定了 TTWindow 将展示的索引。这些值围绕着UIWindowLevel
,并将窗口展示在原生 Apple 组件如UIStatusBar
或UIAlert
之上或之下
TTWindowManager
根据 MIT 许可证发布。它是由我(thattyson)创建和开发的。