我从苹果公司下载了AVCam示例,并尝试将xib文件迁移到Storyboard。
问题是"newCaptureVideoPreviewLayer“无法在视图中显示视频...视图将outlet引用到"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.
}有人有什么建议吗?
发布于 2013-03-05 21:33:59
您可能希望确保您的camerapreview视图是故事板中的顶子视图。最后添加或使用BringSubviewToFront接口。
我猜如果你按下“拍摄照片”,相机会把一张照片保存到你的相机卷轴上?如果没有,可能是初始化代码有问题。我不得不修改iOS6的ismirrored弃用代码。
https://stackoverflow.com/questions/14337234
复制相似问题