我正在尝试修改Apple的PhotoScroller example以使创建到子视图中的滚动视图成为占据整个屏幕的视图。关于如何实现这一点的任何想法?
- (void)loadView
{
// Step 1: make the outer paging scroll view
CGRect pagingScrollViewFrame = [self frameForPagingScrollView];
pagingScrollView = [[UIScrollView alloc] initWithFrame:pagingScrollViewFrame];
pagingScrollView.pagingEnabled = YES;
pagingScrollView.backgroundColor = [UIColor blackColor];
pagingScrollView.showsVerticalScrollIndicator = NO;
pagingScrollView.showsHorizontalScrollIndicator = NO;
pagingScrollView.contentSize = [self contentSizeForPagingScrollView];
pagingScrollView.delegate = self;
// When I do this it fails
[self.view addSubview:pagingScrollView];
// Step 2: prepare to tile content
recycledPages = [[NSMutableSet alloc] init];
visiblePages = [[NSMutableSet alloc] init];
[self tilePages];
}
答案 0 :(得分:0)
您只需要修改滚动视图的框架,使其定位并调整大小:
这是视图控制器中的一行,它在示例中设置了
pagingScrollView = [[UIScrollView alloc] initWithFrame:pagingScrollViewFrame];
这里的示例是一个带有一些硬编码值的示例帧:
CGRect scrollFrame = CGRectMake(100,100,100,100);
pagingScrollView = [[UIScrollView alloc] initWithFrame:scrollFrame];
答案 1 :(得分:0)
因此,我发现通过将方法从loadView更改为viewDidLoad,我可以将scrollView添加为子视图。
我不知道为什么会这样,但确实如此。我很想知道为什么会这样......