所以我有一个滚动视图,其中有 3 个其他视图作为子视图。使用滚动视图在 3 个子视图之间进行分页,这些子视图的控制器存储在数组中。
- (void)viewDidLoad
{
[self loadData];
self.uiScrollView = [[UIScrollView alloc] initWithFrame:self.view.frame];
[self.uiScrollView setPagingEnabled:YES];
[self.uiScrollView setContentSize:CGSizeMake(self.view.frame.size.width*3, self.view.frame.size.height)];
self.uiScrollView.delegate = self;
[self.view addSubview:self.uiScrollView];
self.uiPhotoCollectionViewControllers = [[NSMutableArray alloc] init];
int numberOfOtherViews = 3;
int subViewOffset = 0;
for (int i = 0; i < numberOfCollectionViews; i++)
{
UIViewController* uiViewController = [[UIPhotoCollectionViewController alloc] initWithData:dataArray];
// add offset to the view of the controller
[self.uiScrollView addSubview:uiViewController.view];
[self.uiViewControllers addObject:uiViewController];
uiViewController.view.frame = CGRectOffset(uiViewController.view.frame,subViewOffset,0.0f);
subViewOffset = subViewOffset + uiViewController.view.frame.size.width;
}
如果我以后想用第一个视图切换滚动视图中间的视图,我将如何在不删除所有滚动视图子视图并替换它们的情况下进行此操作。