问题描述
我在横向模式下播放视频.当设备方向改变时,视图只会在 LandscapeLeft 和 LandscapeRight 之间旋转.也就是说在播放电影时没有纵向模式.更何况除了电影视图,其他视图都是纵向模式,所以应用程序配置是纵向的.如何使电影视图仅在横向模式下旋转.
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.
应用委托,
internal var shouldRotate = false
func application(_ application: UIApplication,
supportedInterfaceOrientationsFor window: UIWindow?) -> UIInterfaceOrientationMask {
return shouldRotate ? .allButUpsideDown : .portrait
}
电影视图控制器,
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.
推荐答案
将 .allButUpsideDown
更改为 .landscape
func application(_ application: UIApplication,
supportedInterfaceOrientationsFor window: UIWindow?) -> UIInterfaceOrientationMask {
return shouldRotate ? .landscape : .portrait
}
这篇关于仅在 LandscapeLeft 和 LandscapeRight 之间旋转的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!