I am creating a game in iOS with Spritekit and I want my game to be in landscape orientation only. However every time I test my game in the simulator it always loads up in portrait orientation no matter what I try. I have read many stack overflow post on this issue and I have tried the following with no success:
GameViewController
override var shouldAutorotate: Bool {
return false
}
override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
return [UIInterfaceOrientationMask.landscapeLeft, UIInterfaceOrientationMask.landscapeLeft]
}
Please note I have also tried switching Autorotate from true to false. This did not work either.
Xcode project file
Info.plist
None of this has worked
Try adding this function:
func navigationControllerSupportedInterfaceOrientations(_ navigationController: UINavigationController) -> UIInterfaceOrientationMask {
return UIInterfaceOrientationMask.portrait
}
Use UIInterfaceOrientationMask
for setting up orientation.
private var orientations = UIInterfaceOrientationMask.landscapeLeft
override var supportedInterfaceOrientations : UIInterfaceOrientationMask {
get { return self.orientations }
set { self.orientations = newValue }
}
override func viewDidLoad() {
super.viewDidLoad()
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.