我创建了一个摄像机视图,通过创建AVCaptureVideoPreviewLayer
来显示在屏幕上,现在我希望它能够显示在我的滚动视图中。目前我的滚动视图设置为处理UIImageViews,但不是相机层。以下是它们如何一起工作的:UIScrollView显示摄像机
//设置摄像头视图 [self setCaptureManager:[[CaptureManager alloc] init]];
[[self captureManager] addVideoInput];
[[self captureManager] addVideoPreviewLayer];
CGRect layerRect = [[[self view] layer] bounds];
[[[self captureManager] previewLayer] setBounds:layerRect];
[[[self captureManager] previewLayer] setPosition:CGPointMake(CGRectGetMidX(layerRect),
CGRectGetMidY(layerRect))];
[[[self view] layer] addSublayer:[[self captureManager] previewLayer]];
[[captureManager captureSession] startRunning];
int PageCount = 2;
NSMutableArray *arrImageName =[[NSMutableArray alloc]initWithObjects:settingsView,captureManager,nil];
UIScrollView *scroller = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
scroller.scrollEnabled=YES;
scroller.backgroundColor = [UIColor clearColor];
[scroller setShowsHorizontalScrollIndicator:NO];
scroller.pagingEnabled = YES;
scroller.bounces = NO;
scroller.delegate = self;
[self.view addSubview:scroller];
int width=scroller.frame.size.width;
int xPos=0;
for (int i=0; i<PageCount; i++)
{
UIView *view1 = [[UIView alloc]initWithFrame:CGRectMake(xPos, 0, scroller.frame.size.width, scroller.frame.size.height)];
UIView *view2 = [arrImageName objectAtIndex:i];
[view1 addSubview:view2];
[scroller addSubview:view1];
scroller.contentSize = CGSizeMake(width, 0);
width +=scroller.frame.size.width;
xPos +=scroller.frame.size.width;
}
捕获管理器处理AVCaptureVideoPreviewLayer
,这一切都正常工作,并自行显示。我试图让它出现在我的scrollView
里面,所以我已经注释掉了CGRect
layerRect
,而是试图让它在我的数组中显示在scrollView
上。在scrollView
的底部,我有一个UIImageView
正在采取数组并显示它,但是这不会显然工作,因为相机不是图像。我可以改变或研究底部做什么工作?将其更改为UIView
?谢谢。
嘿!感谢所以我编辑了代码,并将其更改为一个UIView和即时通讯关闭,但我得到错误''NSInvalidArgumentException',原因:' - [CaptureManager超级检视]:任何想法? – Inovize
请参阅编辑答案。 –
这解决了superview问题,它工作没有错误,但现在它不显示任何东西,但从我viewController的白色屏幕。尽管我认为它很接近! – Inovize