加载故事板时的方向问题 - iOS

时间:2014-12-20 07:36:24

标签: swift ios8 uiinterfaceorientation xcode6.1 ios8.1

我在AppDelegate的didFinishLaunching方法中创建了一个视图控制器,并将其分配给窗口的根视图控制器。

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
        // Override point for customization after application launch.
        window = UIWindow(frame: UIScreen.mainScreen().bounds) // issue with allocating UIWindow
        self.viewController = AKSidePanelController()

        self.viewController!.centerPanel = UINavigationController(rootViewController: UIStoryboard.centerViewController()!)

        window!.rootViewController = self.viewController
        window!.makeKeyAndVisible()
        return true
    }



func shouldAutorotate() -> Bool {
        return true
    }

    func supportedInterfaceOrientations() -> Int {
        return UIInterfaceOrientation.Portrait.rawValue | UIInterfaceOrientation.LandscapeLeft.rawValue | UIInterfaceOrientation.LandscapeRight.rawValue
    }

由于某些原因,自动旋转无效。我认为问题是因为在didfinishlaunching中分配窗口。当我尝试直接从storyboard启动时(通过标记isInitialViewController = yes)而不在didFinishLaunching上添加任何代码,自动旋转工作。如您所见,我需要加载“viewController”作为rootviewcontroller。我做错了什么?

我正在使用Xcode 6.1

Landscape

enter image description here

1 个答案:

答案 0 :(得分:0)

问题在于我从故事板加载View以及在App委托中的didFinishLaunchingOption中初始化视图控制器。解决方案是避免从故事板加载初始视图。

将IsinitialViewController设置为no并从appdelegate加载视图控制器

这个帮我解决了这个问题。 Programmatically set the initial view controller using Storyboards

请注意,您必须在plist中将“主故事板文件基本名称”设为空。