背景
我有一个使用AVFoundation的应用程序以拥有自定义相机。这发生在中OCRViewController。当我拍照时,会将捕获的图片发送到其他视图ImagePreviewViewController。
我使用Xcode 10.2.1 (10E1001)与Swift 5
目标
我想实现的是将的方向锁定ImagePreviewViewController为图像的原始方向。我已经知道如何获取图像的方向,但是我无法锁定视图的方向。
我得到这样的图像旋转: let imageOri = capturedImage?.imageOrientation
我尝试了什么?
我尝试了其他来源的公认答案:
在https://developer.apple.com/documentation/uikit/uiviewcontroller#//apple_ref/occ/instm/UIViewController/supportedInterfaceOrientations下的“ 处理视图旋转 ” 下阅读文档,内容如下:
在编写此查询时,我还尝试了许多建议的解决方案,但是,大多数方法似乎使用以下方法(或它的一种变体),它对我不起作用。
override func supportedInterfaceOrientations() -> Int {
return Int(UIInterfaceOrientationMask.Portrait.rawValue)
}
override func shouldAutorotate() -> Bool{
return false
}
override func preferredInterfaceOrientationForPresentation() -> UIInterfaceOrientation {
return UIInterfaceOrientation.Portrait
}
Run Code Online (Sandbox Code Playgroud)
从iOS 8开始,不推荐使用所有与旋转相关的方法。相反,旋转被视为视图控制器视图大小的变化,因此使用viewWillTransition(to:with :)方法进行报告。
但是,我不确定如何从这里开始。
有趣的代码片段
我的中使用了以下方法OCRViewController,在此实例化ImagePreviewViewController并附加捕获的图像。
func displayCapturedPhoto(capturedPhoto : UIImage) {
let imagePreviewViewController = storyboard?.instantiateViewController(withIdentifier: "ImagePreviewViewController") …Run Code Online (Sandbox Code Playgroud)