UIScrollView显示相机

我创build了一个摄像头视图,通过创build一个AVCaptureVideoPreviewLayer来显示在屏幕上,现在我希望能够在我的滚动视图中显示。 目前我的滚动视图设置为处理UIImageViews而不是相机层。 这是如何一起工作的:

//设置摄像头视图[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; } 

捕获pipe理器处理AVCaptureVideoPreviewLayer ,这一切都正常工作,并自行显示。 我试图让它显示在我的scrollView所以我已经注释了CGRect layerRect ,而是试图让它显示在我的数组scrollView 。 在scrollView的底部,我有一个UIImageView正在采取数组并显示它,但是这将不会显然工作,因为相机不是一个图像。 我可以改变或研究底部做什么工作? 将其更改为UIView ? 谢谢。

在循环之后,只需在UIScrollView的底部创build并添加UIView (使用正确的位置和矩形)。 然后,将video预览图层添加为添加到scrollView的视图的子图层。 祝你好运!

编辑好吧,试试这个:

 [[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))]; UIView *captureView = [[UIView alloc] initWithFrame:self.view.bounds]; [[captureView layer] addSublayer:[[self captureManager] previewLayer]]; [[captureManager captureSession] startRunning]; int PageCount = 2; NSMutableArray *arrImageName =[[NSMutableArray alloc]initWithObjects:settingsView,captureView,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; }