我从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.
}
有人有消化吗?
答案 0 :(得分:0)
您可能需要确保您的camerapreview视图是故事板中的顶级子视图。最后添加或使用BringSubviewToFront api。
如果您按拍照,我猜相机正在将照片保存到照片相机胶卷?如果没有,它可能是init代码的问题。我不得不更改ios 6的ismirrored弃用代码。