2013-10-18 44 views
0

我创建了一个摄像机视图,通过创建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里面,所以我已经注释掉了CGRectlayerRect,而是试图让它在我的数组中显示在scrollView上。在scrollView的底部,我有一个UIImageView正在采取数组并显示它,但是这不会显然工作,因为相机不是图像。我可以改变或研究底部做什么工作?将其更改为UIView?谢谢。

回答

1

完成循环后,只需在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; 
} 
+0

嘿!感谢所以我编辑了代码,并将其更改为一个UIView和即时通讯关闭,但我得到错误''NSInvalidArgumentException',原因:' - [CaptureManager超级检视]:任何想法? – Inovize

+0

请参阅编辑答案。 –

+0

这解决了superview问题,它工作没有错误,但现在它不显示任何东西,但从我viewController的白色屏幕。尽管我认为它很接近! – Inovize

相关问题