0

我从 Apple 下载了 AVCam 示例,并尝试将 xib 文件迁移到 Storyboard。

问题是“newCaptureVideoPreviewLayer”没有在视图中显示视频......视图正在引用“videoPreviewView”的出口,这是视频应该出现的视图。

这是 AVCam 示例中的代码,我只是粘贴了代码并删除了不必要的代码:

- (void)viewDidLoad
{
    if ([self captureManager] == nil) {
    AVCamCaptureManager *manager = [[AVCamCaptureManager alloc] init];
    [self setCaptureManager:manager];
    [manager release];

    [[self captureManager] setDelegate:self];

    if ([[self captureManager] setupSession]) {
        // Create video preview layer and add it to the UI
        AVCaptureVideoPreviewLayer *newCaptureVideoPreviewLayer = [[AVCaptureVideoPreviewLayer alloc] initWithSession:[[self captureManager] session]];
        UIView *view = [self videoPreviewView];
        CALayer *viewLayer = [view layer];
        [viewLayer setMasksToBounds:YES];

        CGRect bounds = [view bounds];
        [newCaptureVideoPreviewLayer setFrame:bounds];

        [newCaptureVideoPreviewLayer setVideoGravity:AVLayerVideoGravityResizeAspectFill];

        [viewLayer insertSublayer:newCaptureVideoPreviewLayer below:[[viewLayer sublayers] objectAtIndex:0]];

        [self setCaptureVideoPreviewLayer:newCaptureVideoPreviewLayer];
        [newCaptureVideoPreviewLayer release];

        // Start the session. This is done asychronously since -startRunning doesn't return until the session is running.
        dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
            [[[self captureManager] session] startRunning];
        });
    }
}

[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}

有人有建议吗?

4

1 回答 1

0

您可能希望确保您的 camerapreview 视图是故事板中的顶部子视图。最后添加它或使用 BringSubviewToFront api。

如果您按拍照,我猜相机正在将照片保存到您的照片相机胶卷中?如果不是,它可能是初始化代码的问题。我不得不更改 ios 6 的 ismirrored 已弃用代码。

于 2013-03-05T13:33:59.257 回答