簡體   English   中英

錯誤-缺少預期返回'UIInterfaceOrientationMask'的函數中的返回

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

類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'的函數中的return}

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

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

}

你的函數supportedInterfaceOrientations只返回正確的類型,如果UIDevice.currentDevice().userInterfaceIdiom == .Phone 它需要的在返回結果else的that從句if太。

您需要處理

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM