1

我试图让相机显示在滚动视图上,就像 snapchat 的滑动导航一样。我试图像下面这样设置它,在其中创建要显示的对象数组,其中相机是其中之一,然后将其设置为我的滚动条的子视图。此代码可以正常工作,但屏幕上没有显示任何内容。谁能帮我看看我可能做错了什么。我认为这可能是添加子视图。我应该改用页面视图吗?有没有人尝试制作类似于 snapchat 的 UI 并且可以提供一些链接?谢谢

//Set Up the Camera View
    [[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;
    }
4

1 回答 1

1

以此为例说明如何在页面控制器中处理多个页面:

https://developer.apple.com/library/ios/samplecode/PhotoScroller/Introduction/Intro.html#//apple_ref/doc/uid/DTS40010080

于 2013-10-28T10:28:28.147 回答