我对iOS编码很新,所以我使用了一些我在github上找到的库。我有一个加载弹出UIDatePicker的工作正常,直到我添加代码来选择应用首次启动时加载哪个视图。这是我能找到的所有相关代码。任何帮助将不胜感激。
来自DatePickerDialog:
func countScreenSize() -> CGSize {
var screenWidth = UIScreen.mainScreen().bounds.size.width
var screenHeight = UIScreen.mainScreen().bounds.size.height
let interfaceOrientaion = UIApplication.sharedApplication().statusBarOrientation
if UIInterfaceOrientationIsLandscape(interfaceOrientaion) {
let tmp = screenWidth
screenWidth = screenHeight
screenHeight = tmp
}
return CGSizeMake(screenWidth, screenHeight)
}
override init() {
super.init(frame: CGRectMake(0, 0, UIScreen.mainScreen().bounds.size.width, UIScreen.mainScreen().bounds.size.height))
NSNotificationCenter.defaultCenter().addObserver(self, selector: "deviceOrientationDidChange:", name: UIDeviceOrientationDidChangeNotification, object: nil)
}
以下是我添加到app delegate的代码,用于选择要加载的视图:
if currentUser != nil {
var storyboard = UIStoryboard(name: "Main", bundle: nil)
var initialViewController = storyboard.instantiateViewControllerWithIdentifier("loggedin") as UIViewController
self.window?.rootViewController = initialViewController
self.window?.makeKeyAndVisible()
} else {
var storyboard = UIStoryboard(name: "Main", bundle: nil)
var initialViewController = storyboard.instantiateViewControllerWithIdentifier("start") as UIViewController
self.window?.rootViewController = initialViewController
self.window?.makeKeyAndVisible()
}