Ios UIScrollView显示摄像机

Ios UIScrollView显示摄像机,ios,objective-c,avcapturesession,Ios,Objective C,Avcapturesession,我通过创建AVCaptureVideoPreviewLayer创建了一个要在屏幕上显示的摄像头视图,现在我希望它能够显示在我的滚动视图中。当前,我的滚动视图设置为处理UIImageView,但不处理相机层。以下是它们如何协同工作: //设置摄影机视图 [self-setCaptureManager:[[CaptureManager alloc]init]] [[self captureManager] addVideoInput]; [[self captureManager] addVide

我通过创建
AVCaptureVideoPreviewLayer
创建了一个要在屏幕上显示的摄像头视图,现在我希望它能够显示在我的滚动视图中。当前,我的滚动视图设置为处理UIImageView,但不处理相机层。以下是它们如何协同工作:

//设置摄影机视图 [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;
}
[[self captureManager]添加视频输入];
[[self captureManager]addVideoPreviewLayer];
CGRect layerRect=[[[self view]layer]bounds];
[[self captureManager]预览层]挫折:层更正];
[[[self captureManager]previewLayer]设置位置:CGPointMake(CGRectGetMidX(layerRect),
CGRectGetMidY(layerRect))];
[[[self-view]层]添加子层:[[self-captureManager]预览层]];
[[captureManager captureSession]开始计时];
int PageCount=2;
NSMutableArray*arrImageName=[[NSMutableArray alloc]initWithObjects:settingsView,captureManager,nil];
UIScrollView*scroller=[[UIScrollView alloc]initWithFrame:CGRectMake(0,0320480)];
scroller.scrollEnabled=是;
scroller.backgroundColor=[UIColor clearColor];
[滚动条设置ShowShorizontalsCrollinIndicator:否];
scroller.PaginEnabled=是;
scroller.bounces=否;
scroller.delegate=self;
[self.view addSubview:scroller];
int width=scroller.frame.size.width;
int xPos=0;

对于(int i=0;i在循环之后,只需在
UIScrollView
的底部创建并添加
UIView
(具有适当的位置和矩形)。然后,将视频预览层作为子层添加到添加到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;
}
[[self captureManager]添加视频输入];
[[self captureManager]addVideoPreviewLayer];
CGRect layerRect=[[[self view]layer]bounds];
[[self captureManager]预览层]挫折:层更正];
[[[self captureManager]previewLayer]设置位置:CGPointMake(CGRectGetMidX(layerRect),
CGRectGetMidY(layerRect))];
UIView*captureView=[[UIView alloc]initWithFrame:self.view.bounds];
[[captureView层]添加子层:[[self captureManager]预览层]];
[[captureManager captureSession]开始计时];
int PageCount=2;
NSMutableArray*arrImageName=[[NSMutableArray alloc]initWithObjects:settingsView,captureView,nil];
UIScrollView*scroller=[[UIScrollView alloc]initWithFrame:CGRectMake(0,0320480)];
scroller.scrollEnabled=是;
scroller.backgroundColor=[UIColor clearColor];
[滚动条设置ShowShorizontalsCrollinIndicator:否];
scroller.PaginEnabled=是;
scroller.bounces=否;
scroller.delegate=self;
[self.view addSubview:scroller];
int width=scroller.frame.size.width;
int xPos=0;

对于(int i=0;iHey!谢谢,因此我编辑了代码并将其更改为UIView,im关闭,但我收到了错误
'NSInvalidArgumentException',原因:'-[CaptureManager superview]:
有什么想法吗?这解决了superview的问题,它工作正常,但现在除了我的viewController中的白色屏幕外,它什么也不显示。不过我认为它很接近了!