【问题标题】:Rotate only between landscapeLeft and landscapeRight仅在 LandscapeLeft 和 LandscapeRight 之间旋转
【发布时间】:2017-05-03 05:58:40
【问题描述】:

我在横向模式下播放视频。当设备方向改变时,视图只会在 LandscapeLeft 和 LandscapeRight 之间旋转。也就是说播放电影时没有人像模式。更何况除了电影视图,其他视图都是纵向模式,所以应用配置是纵向的。如何使电影视图仅在横向模式下旋转。

这是我的代码的一部分。

应用程序代理,

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")

目前的问题是当方向改变时电影视图可能是纵向的。

【问题讨论】:

    标签: ios uiview swift3 screen-orientation uiinterfaceorientation


    【解决方案1】:

    .allButUpsideDown 更改为.landscape

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

    【讨论】:

      猜你喜欢
      • 2017-05-11
      • 1970-01-01
      • 1970-01-01
      • 2013-02-27
      • 1970-01-01
      • 2013-06-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多