[英]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.