2013-10-18 1 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을 처리하고,이 모두는 그 자체로 잘 작동하고 표시합니다. 나는 layerRect을 주석 처리하고 그 대신 내 배열 scrollView에 표시하려고하고 있으므로 내 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 superview] :'어떤 아이디어? – Inovize

+0

수정 된 답변을 참조하십시오. –

+0

그건 superview 문제를 해결하고 지금은 내 viewController에서 흰색 화면 이외의 아무것도 표시하지 않고 오류없이 작동하고 있습니다. 나는 그것의 가까운 생각한다! – Inovize

관련 문제