0

我试图找出在 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];
4

1 回答 1

1

从您添加的代码中,两个视图位于同一位置,一个在另一个之上。添加第二个视图时,您应该更改其框架原点以将其定位在第一个视图旁边。

于 2013-06-27T23:24:07.477 回答