我试图找出在 UIScrollView 中实现多个 UIViewControllers 的最佳方法。现在,我手动启动我的 UIViewController 并将其作为子视图添加到 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];