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

六月ゝ 毕业季﹏ 提交于 2019-11-26 21:40:09

问题


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


回答1:


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.




回答2:


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




回答3:


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.



来源:https://stackoverflow.com/questions/32684922/ios9-alternative-to-uidevice-currentdevice-setvalue-to-force-orientation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!