我正在尝试找出在UIScrollView中实现多个UIViewControllers的最佳方法。现在,我手动启动我的UIViewController并将其作为子视图添加到Scrollview。这工作正常,但即使滚动到右侧后,scrollview也不会显示多于一个UIViewController。知道为什么会这样吗?这是我的代码:
DTArticle *article = [self.articles objectAtIndex:0];
DTArticle *article2 = [self.articles objectAtIndex:1];
UIStoryboard *mainStoryBoard = [UIStoryboard storyboardWithName:@"MainStoryboard_iPhone" bundle:nil];
DTArticleViewController *controller = [mainStoryBoard instantiateViewControllerWithIdentifier:@"DTArticleViewController"];
DTArticleViewController *controller2 = [mainStoryBoard instantiateViewControllerWithIdentifier:@"DTArticleViewController"];
controller.article = article;
controller2.article = article2;
[self.parentScrollView addSubview:controller.view];
[self.parentScrollView addSubview:controller2.view];
self.parentScrollView.contentSize = CGSizeMake(self.parentScrollView.frame.size.width
* 2, self.parentScrollView.frame.size.height);
self.parentScrollView.showsHorizontalScrollIndicator = YES;
[self.parentScrollView setPagingEnabled:YES];
[self.view addSubview:self.parentScrollView];
答案 0 :(得分:1)
根据您添加的代码,两个视图位于同一位置,一个位于另一个位置之上。添加第二个视图时,应更改其帧原点,使其位于第一个视图旁边。