【问题标题】:Orientation issue when loading storyboard - iOS加载故事板时的方向问题 - iOS
【发布时间】:2014-12-20 07:36:24
【问题描述】:

我在 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 中分配了窗口。当我尝试直接从情节提要启动(通过标记 isInitialViewController = yes)而不在 didFinishLaunching 上添加任何代码时,自动旋转工作。如您所见,我需要将“viewController”加载为 rootviewcontroller。我做错了什么?

我使用的是 Xcode 6.1

【问题讨论】:

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


    【解决方案1】:

    问题是我正在从情节提要加载视图以及在 App 委托的 didFinishLaunchingOption 中初始化视图控制器。解决方案是避免从情节提要加载初始视图。

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

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

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

    【讨论】:

      猜你喜欢
      • 2012-01-30
      • 1970-01-01
      • 1970-01-01
      • 2015-12-29
      • 1970-01-01
      • 1970-01-01
      • 2012-05-28
      • 2012-06-25
      相关资源
      最近更新 更多