我需要检查用户是否已登录,并相应地重定向它们。将此代码添加到我的应用代理后,我的应用程序将永久停留在纵向模式下,并且不会以横向渲染。我做错了什么?我听说过没有正确设置根视图,或添加子视图或容器等等问题。下面有什么东西看起来不正确可能导致我像我一样被卡住了吗?
谢谢!
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: NSDictionary?) -> Bool {
//Redirect user to either home screen, or login/register screen
self.window = UIWindow(frame: UIScreen.mainScreen().bounds)
var storyboard = UIStoryboard(name: "Main", bundle: nil)
var initialViewController = storyboard.instantiateViewControllerWithIdentifier("vcLoginGateway") as UIViewController
var userSettings = UserSettings()
//Change gateway view controller to the home view controller if logged in
if (userSettings.IsUserLoggedIn()) {
initialViewController = storyboard.instantiateViewControllerWithIdentifier("vcHome") as UIViewController
}
self.window?.rootViewController = initialViewController
self.window?.makeKeyAndVisible()
return true
}
答案 0 :(得分:1)
所以我最终使我的登录网关成为初始视图控制器,然后在app委托中检查:
if (userSettings.IsUserLoggedIn()) {
var initialViewController = storyboard.instantiateViewControllerWithIdentifier("vcHome") as UITabBarController
self.window!.rootViewController = initialViewController
}
现在它仅检查您是否已登录,如果是,则相应地重定向您。这工作,现在我可以旋转我的设备!真棒。谢谢大家
答案 1 :(得分:0)
您是否检查过“设备方向”是否已选中“左侧风景”和“右侧风景”?检查构建目标 - >常规 - >部署信息 - >设备方向
答案 2 :(得分:0)
请检查一下:
var initialViewController = storyboard.instantiateViewControllerWithIdentifier("vcLoginGateway") as UIViewController
var userSettings = UserSettings()
//Change gateway view controller to the home view controller if logged in
if (userSettings.IsUserLoggedIn()) {
initialViewController = storyboard.instantiateViewControllerWithIdentifier("vcHome") as UIViewController
}
你把它们都作为UIViewController但是你应该这样做,假设你的ViewCOntroller的名字是NameOfYouViewController
,所以你应该写:
initialViewController = storyboard.instantiateViewControllerWithIdentifier("vcHome") as NameOfYouViewController
希望这会有所帮助.. :)