我有两个视图控制器,我想将此添加为滚动视图的子视图,但是,当我添加这些视图控制器时,仅显示第二个控制器。
这是我的代码。
- (void)viewDidLoad
{
UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 320, 460)];
[self.view addSubview:scrollView];
[scrollView setBounces:NO];
scrollView.pagingEnabled = YES;
scrollView.contentSize = CGSizeMake(320*2, 460);
controllers = [[NSMutableArray alloc] initWithCapacity:0];
First *first = [self.storyboard instantiateViewControllerWithIdentifier:@"First"];
[scrollView addSubview:first.view];
[controllers addObject:first];
Second *second = [self.storyboard instantiateViewControllerWithIdentifier:@"Second"];
[scrollView addSubview:second.view];
[controllers addObject:second];
}
提前致谢。
仅举一个例子,您可以根据需要调整其框架。
- (void)viewDidLoad
{
UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 320, 460)];
[self.view addSubview:scrollView];
[scrollView setBounces:NO];
scrollView.pagingEnabled = YES;
scrollView.contentSize = CGSizeMake(320*2, 460);
controllers = [[NSMutableArray alloc] initWithCapacity:0];
First *first = [self.storyboard instantiateViewControllerWithIdentifier:@"First"];
[scrollView addSubview:first.view];
first.view.frame = CGRectMake(0.0, 0.0, 320.0, 460.0) ;
[controllers addObject:first];
Second *second = [self.storyboard instantiateViewControllerWithIdentifier:@"Second"];
[scrollView addSubview:second.view];
second.view.frame = CGRectMake(320.0, 0.0, 320.0, 460.0) ;
[controllers addObject:second];
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句