0

我已经创建了一个要在屏幕上显示的相机视图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;
}

捕获管理器处理AVCaptureVideoPreviewLayer所有这些都可以正常工作并自行显示。我试图让它显示在我的内部scrollView,所以我已经注释掉了CGRect layerRect,而是试图让它显示在我的数组中scrollView。在底部scrollView,我有一个UIImageView正在获取数组并显示它,但是这显然不会工作,因为相机不是图像。我可以在底部进行哪些更改或查看以使其正常工作?将其更改为UIView? 谢谢你。

4

1 回答 1

1

在您的循环之后,只需在您UIView的底部创建并添加UIScrollView(具有适当的位置和矩形)。然后,将视频预览层作为子层添加到添加到滚动视图的视图中。祝你好运!

编辑 好的,试试这个:

[[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;
}
于 2013-10-18T07:15:08.917 回答