且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

UIScrollView显示相机

更新时间:2023-12-02 10:25:52

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

After your loop, just create and add UIView at the bottom of the your UIScrollView (with proper position and rect). Then, add video preview layer as a sublayer to the view added to the scrollView. Good Luck!

编辑
ok,试试这个:

EDIT ok, try this:

[[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;
}