ios - 如何使用 swift 以纵向模式捕获图像
问题描述
我已经使用了 Apple 的 AVCam 模型,并在我的相机应用程序中实现了肖像模式。但问题是拍摄的图像不会是人像模式,而是像普通相机拍摄的那样。后来我发现我可以通过进入编辑部分并选择“人像”选项来激活人像模式。我希望以纵向模式保存图片。我怎样才能做到这一点?
解决方案
import UIKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
NotificationCenter.default.addObserver(self, selector: #selector(MainCameraVC.orientationChanged(notification:)), name: Notification.Name.UIDeviceOrientationDidChange, object: nil)
}
func orientationChanged(notification: Notification) {
let deviceOrientation = UIDevice.current.orientation
var angle: Double?
switch deviceOrientation {
case .portrait:
angle = 0
break
case .portraitUpsideDown:
angle = Double.pi
break
case .landscapeLeft:
angle = Double.pi / 2
break
case .landscapeRight:
angle = -Double.pi / 2
break
default:
break
}
if let angle = angle {
let transform = CGAffineTransform(rotationAngle: CGFloat(angle))
UIView.animate(withDuration: 0.3, animations: {
self.label.transform = transform
self.button.transform = transform
...
})
}
}
}
推荐阅读
- cassandra - Cassandra RangeError:试图访问超出缓冲区长度
- phantomjs - 在 Linux 上安装 PhantomJs
- python - websocket 和 websocket-client,如何同时使用?
- reactjs - React原生组件中的高阶组件(HOC)和继承有什么区别
- ios - 用于为所有 URLRequest 添加自定义标头字段的 URLRequest 和 URLSession 拦截器?
- c# - Emgu cv高分辨率图像拼接问题
- replace - 如何在fluentd中用特定字符串替换键值字符串
- c# - 从 Android 项目的 Forms 项目中的 EmbeddedResource 获取图片
- swift - 需要移动 uicollectionview 单元格内的单元格 && Textfield 图像添加
- php - 生物识别指纹同步套接字错误 - PHP