var positionBack:Bool = false
func changeCamera() {
// 摄像头翻转动画
let animation: CATransition = CATransition.init()
animation.duration = 1.0
animation.timingFunction = CAMediaTimingFunction.init(name: kCAMediaTimingFunctionEaseOut)
animation.type = "oglFlip"
session.stopRunning()
// 首先移除所有的 input
if let allInputs = session.inputs as? [AVCaptureDeviceInput] {
for input in allInputs {
session.removeInput(input)
}
}
positionBack = !positionBack
if !positionBack {
animation.subtype = kCATransitionFromLeft
videoDevice = cameraWithPosition(position: .front)
} else {
animation.subtype = kCATransitionFromRight
videoDevice = cameraWithPosition(position: .back)
}
// 添加翻转动画
self.view.layer.add(animation, forKey: nil)
// 会话中添加视音频
if let videoInput = try? AVCaptureDeviceInput(device: videoDevice) {
session.addInput(videoInput)
}
if let videoInput = try? AVCaptureDeviceInput(device: audioDevice) {
session.addInput(videoInput)
}
session.startRunning()
}
func cameraWithPosition(position: AVCaptureDevicePosition) -> AVCaptureDevice? {
// 设置前置或者后置摄像头
let devices = AVCaptureDevice.devices(withMediaType: AVMediaTypeVideo)
for item in devices as! [AVCaptureDevice] {
if item.position == position {
return item
}
}
return nil
}
swift随手记-摄像头翻转动画
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
推荐阅读更多精彩内容
- 整理了下Vuforia 6-2-10 版本对应识别功能的函数 TrackableSettings类主要功能开启扩展...
- 最近在做直播推流方面的工作,因为需要添加美白,滤镜,AR贴图等效果。所以不能简单的使用SufaceView加C...
- 转载:http://blog.csdn.net/enjolras1024/article/details/7347...
- 1.利用手势滑动UIPanGestureRecognizer 判断手势拖动的坐标2.利用CATransform3D...