简体   繁体   中英

iOS9: Alternative to UIDevice.currentDevice().setValue(…) to force orientation

It seems to me this does not work anymore in iOS9. It was the de facto way of forcing orientation changes based my SO research. It now freezes my SpriteKit game.

Is it just me, and if not does anyone know of an alternative?

EDIT : Portrait and UpsideDown still work. It seems only Landscape modes now cause a freeze

EDIT 2: Actually I think you can go Portrait <--> UpsideDown and LandscapeLeft <--> LandscapeRight, but not in between them

Adding to Alex's answer: My experience is that Apple only blocks the orientation change for iOS9 iPads that don't require fullscreen. So if you tell the app to require fullscreen, the rotation should work:

在此输入图像描述

However, I have no clue whether it'll solve your SpriteKit freeze since in my experience iOS9 also introduced plenty of SpriteKit bugs.

You are right. Setting the device orientation is not possible on iOS 9. I think this is because of the new SplitScreen Mode on iPad. Now there can be 2 Applications at once on screen and it would be "unfair" for the one Application to decide which orientation is allowed. Imagine two Apps which force different orientations, what would happen? I think Apple just prohibits it in general even though they could limit to iPad non-fullscreen Applications

If you have two or more ViewControllers,and you want each of the ViewControllers has different orientation, I think the best way to force the orientation of the VC is to use these code below:

let value = UIInterfaceOrientation.LandscapeLeft.rawValue
// let value = UIInterfaceOrientation.Portrait.rawValue
UIDevice.currentDevice().setValue(value, forKey: "orientation")

It works for me at iOS 9.

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.

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