Rotate only between landscapeLeft and landscapeRight

守給你的承諾、 提交于 2019-12-23 05:07:33

问题


I have vidoe playing in landscape mode. And the view only rotate between landscapeLeft and landscapeRight when the device orientation changes. That's to say there is no portrait mode when playing the movie. What's more apart from the movie view, other views are portraint mode, so the app config is portrait. How can I make the movie view only rotate in the landscape mode.

Here is a part of my code.

appdelegate,

internal var shouldRotate = false

func application(_ application: UIApplication,
                 supportedInterfaceOrientationsFor window: UIWindow?) -> UIInterfaceOrientationMask {
    return shouldRotate ? .allButUpsideDown : .portrait
}

movie view controller,

    let appDelegate = UIApplication.shared.delegate as! AppDelegate
    appDelegate.shouldRotate = true // or false to disable rotation
    let value = UIInterfaceOrientation.landscapeLeft.rawValue
    UIDevice.current.setValue(value, forKey: "orientation")

For now the problem is that the movie view can be protrait when orientation changes.


回答1:


Change .allButUpsideDown to .landscape

func application(_ application: UIApplication,
                 supportedInterfaceOrientationsFor window: UIWindow?) -> UIInterfaceOrientationMask {
    return shouldRotate ? .landscape : .portrait
}


来源:https://stackoverflow.com/questions/43752132/rotate-only-between-landscapeleft-and-landscaperight

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