admin管理员组

文章数量:1535375

2024年5月24日发(作者:)

iOS AVCaptureVideoPreviewLayer 在 UIView 中没有显示?

iOS AVCaptureVideoPreviewLayer 在 UIView 中没有显示?[英]iOS

AVCaptureVideoPreviewLayer not showing in UIView? The Problem I have a sample

application from Apple (SquareCam) that I’m using as reference to create a

custom

interface for a camera. I’m using the AVFoundation framework. If I build and run the

project from Apple, the app runs as expected. However, if I take the same code from

that

project and place it in a new project in Xcode, the video preview will not display.

我有一个来自 Apple(SquareCam)的示例应用程序,我正在使用它作为参考来为相机

创建自定义界面。我正在使用 AVFoundation 框架。如果我从 Apple 构建并运行该项

目,该应用程序将按预期运行。但是,如果我从该项目中获取相同的代码并将其放在

Xcode 中的新项目中,则不会显示视频预览。

I have simplified the code down to the essential components to run a video preview

layer. Again, this code runs fine as is in the Apple (SquareCam) project, but does

not

display in my new project.

我已将代码简化为运行视频预览图层的基本组件。同样,此代码在

Apple(SquareCam)项目中运行良好,但不会显示在我的新项目中。

The Code - (void)setupAVCapture { NSError *error = nil; AVCaptureSession *session

= [AVCaptureSession new]; if ([[UIDevice currentDevice] userInterfaceIdiom] ==

UIUserInterfaceIdiomPhone)

setSessionPreset:AVCaptureSessionPreset640x480];

[session

else

[session

setSessionPreset:AVCaptureSessionPresetPhoto]; // Select a video device, make an

input

AVCaptureDevice *device = [AVCaptureDevice

AVCaptureDeviceInput defaultDeviceWithMediaType:AVMediaTypeVideo];

*deviceInput = [AVCaptureDeviceInput deviceInputWithDevice:device error: error]; if

([session canAddInput:deviceInput]) [session addInput:deviceInput]; previewLayer =

本文标签: 运行使用视频预览显示