界面切换
界面切换流程图

代码实现
AppDelegate
private func isNewUpdate() -> Bool {
let currentVersion = NSBundle.mainBundle().infoDictionary!["CFBundleShortVersionString"] as! String
let version = NSNumberFormatter().numberFromString(currentVersion)?.doubleValue ?? 0
let versionKey = "versionKey"
let sandboxVersion = NSUserDefaults.standardUserDefaults().doubleForKey(versionKey)
NSUserDefaults.standardUserDefaults().setDouble(version, forKey: versionKey)
return version > sandboxVersion
}
private func defaultController() -> UIViewController {
if sharedUserAccount != nil {
return isNewUpdate() ? NewFeatureViewController() : WelcomeViewController()
}
return MainViewController()
}
window?.rootViewController = defaultController()
多视图控制器切换
定义通知
let HMSwitchMainInterfaceNotification = "HMSwitchMainInterfaceNotification"
NSNotificationCenter.defaultCenter().addObserver(self, selector: "switchRootViewController", name: HMSwitchMainInterfaceNotification, object: nil)
func switchRootViewController(n: NSNotification) {
let isMain = n.object as! Bool
window?.rootViewController = isMain ? MainViewController() : WelcomeViewController()
}
欢迎界面
NSNotificationCenter.defaultCenter().postNotificationName(HMSwitchMainInterfaceNotification, object: true)
新特性界面
NSNotificationCenter.defaultCenter().postNotificationName(HMSwitchMainInterfaceNotification, object: true)
OAuth 用户登录
NSNotificationCenter.defaultCenter().postNotificationName(HMSwitchMainInterfaceNotification, object: false)
self.dismissViewControllerAnimated(true, completion: nil)