【发布时间】:2017-08-18 18:55:33
【问题描述】:
所以我正在使用 Swift 3 和 Xcode 8.3.3 开发 iOS 10 应用程序。 在我的应用程序中,我必须连续拍摄 8 张带有相机指示灯的照片。
所以我将AVCaptureVideoPreviewLayer 用于自定义相机,我需要设置在横向模式下显示相机的视图。
我是用这个扩展来做的,这个扩展是我在搜索问题时在 stackoverflow 上找到的。
struct AppUtility {
static func lockOrientation(_ orientation: UIInterfaceOrientationMask) {
if let delegate = UIApplication.shared.delegate as? AppDelegate {
delegate.orientationLock = orientation
}
}
/// OPTIONAL Added method to adjust lock and rotate to the desired orientation
static func lockOrientation(_ orientation: UIInterfaceOrientationMask, andRotateTo rotateOrientation:UIInterfaceOrientation) {
self.lockOrientation(orientation)
UIDevice.current.setValue(rotateOrientation.rawValue, forKey: "orientation")
}
}
在customCameraView 的viewDidLoad() 中,我将锁定方向设置为.landscapeLeft:
AppUtility.lockOrientation(.landscapeLeft)
在离开视图之前,我在我的 viewWillDissapear 方法中设置它以解锁方向:
AppUtility.lockOrientation(.all)
问题是customCameraView 中的横向模式仅在启用设备的自动旋转(未锁定)并且当我返回上一个视图控制器时才有效,它最初显示在 LandscapeLeft 所以我有转动设备将其置于纵向模式。此视图使用 AppUtility 扩展名锁定为纵向方法。
所以我想总是通过覆盖shouldAutoRotate var 来激活自动旋转,但是当设备自动旋转被锁定时它不起作用。
然后我想确保在打开相机之前启用自动旋转,但是 stackoverflow 上有 100 人说这是不可能的。
所以对我来说,完美的解决方案是始终将 customCameraView 设为 LandscapeLeft 模式,而将之前的视图设为纵向模式,无论是否激活了旋转。
我已经在这个错误上苦苦挣扎了好几天了,如果有一点帮助会很棒。
【问题讨论】:
标签: ios swift3 screen-orientation screen-rotation xcode8