3

可以在 iOS8 自定义键盘的后台打开 AVCaptureVideoPreviewLayer 吗?我试过这段代码

    AVCaptureSession *session = [[AVCaptureSession alloc] init];
AVCaptureDevice *videoDevice = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
if (videoDevice)
{
    NSError *error;
    AVCaptureDeviceInput *videoInput = [AVCaptureDeviceInput deviceInputWithDevice:videoDevice error:&error];
    if (!error)
    {
        if ([session canAddInput:videoInput])
        {
            [session addInput:videoInput];
            AVCaptureVideoPreviewLayer *previewLayer = [AVCaptureVideoPreviewLayer layerWithSession:session];
            previewLayer.frame = self.bounds;
            NSLog(@"open %@",NSStringFromCGRect(self.bounds));
            [self.camView.layer addSublayer:previewLayer];
            [session startRunning];
        }
    }
}

要求允许使用相机,但不要在键盘背景中打开相机。请帮我。谢谢。

4

0 回答 0