错误 - 函数中缺少返回预期返回'UIInterfaceOrientationMask'

时间:2016-02-09 15:25:13

标签: ios swift swift2

类GameViewController:UIViewController {

override func viewDidLoad() {
    super.viewDidLoad()

    if let scene = GameScene.unarchiveFromFile("GameScene") as? GameScene {
        // Configure the view.
        let skView = self.view as! SKView
        skView.showsFPS = false
        skView.showsNodeCount = false

        /* Sprite Kit applies additional optimizations to improve rendering performance */
        skView.ignoresSiblingOrder = true

        /* Set the scale mode to scale to fit the window */
        scene.scaleMode = .AspectFill

        skView.presentScene(scene)
    }
}

override func shouldAutorotate() -> Bool {
    return true
}

override func supportedInterfaceOrientations() -> UIInterfaceOrientationMask {
    if UIDevice.currentDevice().userInterfaceIdiom == .Phone {
        return [UIInterfaceOrientationMask.Portrait, UIInterfaceOrientationMask.PortraitUpsideDown]

    }

//此行有错误 - 函数中缺少返回预期返回'UIInterfaceOrintationMask' }

func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Release any cached data, images, etc that aren't in use.
}

func prefersStatusBarHidden() -> Bool {
    return true
      }
 }

}

2 个答案:

答案 0 :(得分:1)

如果supportedInterfaceOrientations,您的函数UIDevice.currentDevice().userInterfaceIdiom == .Phone仅返回正确的类型。它需要在else的{​​{1}}子句中返回结果。

答案 1 :(得分:0)

您需要处理

UIDevice.currentDevice().userInterfaceIdiom == .Pad
案件也是如此。你可以用这个:

override func supportedInterfaceOrientations() -> UIInterfaceOrientationMask {
    if UIDevice.currentDevice().userInterfaceIdiom == .Phone {
        return [UIInterfaceOrientationMask.Portrait, UIInterfaceOrientationMask.PortraitUpsideDown]
    } else { // I guess this means your userInterfaceIdiom is equal to .Pad
        return [] // here you should return UIInterfaceOrientationMasks you may want to use for Pad devices.
    }
}