简体   繁体   English

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

[英]Error - Missing return in function expected to return 'UIInterfaceOrientationMask'

class GameViewController: UIViewController { 类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]

    }

// this line has the error - missing return in function expected to return 'UIInterfaceOrintationMask' } //此行有错误-缺少预期返回'UIInterfaceOrintationMask'的函数中的return}

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

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

} }

Your function supportedInterfaceOrientations only returns the correct type if UIDevice.currentDevice().userInterfaceIdiom == .Phone . 你的函数supportedInterfaceOrientations只返回正确的类型,如果UIDevice.currentDevice().userInterfaceIdiom == .Phone It needs to return a result in the else clause of that if too. 它需要的在返回结果else的that从句if太。

You need to handle the 您需要处理

UIDevice.currentDevice().userInterfaceIdiom == .Pad

case too. 也是如此。 You can use this: 您可以使用此:

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.
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM