不能把这一个出来.
当应用程序处于活动状态时,一切都可以正常运行,而有时当我将应用程序移动到背景(按住主页按钮)而不是返回时,预览屏幕冻结/卡住.
我使用viewWillAppear和viewDidAppear进行设置.
这是我如何设置一切:
当应用程序处于活动状态时,一切都可以正常运行,而有时当我将应用程序移动到背景(按住主页按钮)而不是返回时,预览屏幕冻结/卡住.
我使用viewWillAppear和viewDidAppear进行设置.
这是我如何设置一切:
var backCamera = AVCaptureDevice.devicesWithMediaType(AVMediaTypeVideo) var global_device : AVCaptureDevice! var captureSession: AVCaptureSession? override func viewWillAppear(animated: Bool) { super.viewWillAppear(animated) captureSession = AVCaptureSession() captureSession!.sessionPreset = AVCaptureSessionPresetPhoto CorrectPosition = AVCaptureDevicePosition.Back for device in backCamera { if device.position == AVCaptureDevicePosition.Back { global_device = device as! AVCaptureDevice CorrectPosition = AVCaptureDevicePosition.Back break } } configureCamera() var error: NSError? var input = AVCaptureDeviceInput(device: global_device,error: &error) if error == nil && captureSession!.canAddInput(input) { captureSession!.addInput(input) stillImageOutput = AVCaptureStillImageOutput() stillImageOutput!.outputSettings = [AVVideoCodecKey: AVVideoCodecJPEG] if captureSession!.canAddOutput(stillImageOutput) { captureSession!.addOutput(stillImageOutput) previewLayer = AVCaptureVideoPreviewLayer(session: captureSession) var bounds:CGRect = camera_Preview.layer.bounds previewLayer?.videoGravity = AVLayerVideoGravityResizeAspectFill previewLayer?.bounds = bounds previewLayer?.position = CGPointMake(CGRectGetMidX(bounds),CGRectGetMidY(bounds)) camera_Preview.layer.addSublayer(previewLayer) self.view.bringSubviewToFront(camera_Preview) self.view.bringSubviewToFront(nan_view) captureSession!.startRunning() } }
ViewDidAppear:
var previewLayer: AVCaptureVideoPreviewLayer? override func viewDidAppear(animated: Bool) { super.viewDidAppear(animated) previewLayer!.frame = camera_Preview.bounds }