swift 中通过AVFoundation来定制拍摄窗口

前端之家收集整理的这篇文章主要介绍了swift 中通过AVFoundation来定制拍摄窗口前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
let devices = AVCaptureDevice.devices().filter{ $0.hasMediaType(AVMediaTypeVideo) && $0.position == AVCaptureDevicePosition.Back }
        if let captureDevice = devices.first as? AVCaptureDevice  {

            do{
                try captureSession.addInput(AVCaptureDeviceInput.init(device: captureDevice))
            }catch let error as NSError {
                logger.error(error.debugDescription)
            }

            captureSession.sessionPreset = AVCaptureSessionPresetPhoto
            captureSession.startRunning()
            stillImageOutput.outputSettings = [AVVideoCodecKey:AVVideoCodecJPEG]
            if captureSession.canAddOutput(stillImageOutput) {
                captureSession.addOutput(stillImageOutput)
            }
            if let previewLayer = AVCaptureVideoPreviewLayer(session: captureSession) {
                previewLayer.frame = view.bounds
                previewLayer.videoGravity = AVLayerVideoGravityResizeAspectFill
                let cameraPreview = UIView(frame: CGRectMake(0.0,0.0,maskBottomView.frame.size.width,maskBottomView.frame.size.height))
                cameraPreview.layer.addSublayer(previewLayer)
                cameraPreview.addGestureRecognizer(UITapGestureRecognizer(target: self,action:"saveToCamera:"))
                maskTopView.layer.cornerRadius = 80;
                maskTopView.layer.shadowOffset = CGSizeMake(15,20);
                maskTopView.layer.shadowRadius = 5;
                maskTopView.layer.shadowOpacity = 0.5;

                view.insertSubview(cameraPreview,belowSubview: maskBottomView)
            }
        }
原文链接:https://www.f2er.com/swift/324275.html

猜你在找的Swift相关文章