1.ScrollView以及在ScrollView上面添加的view,一定不能用layout自动布局,楼主一开始使用Masonry自动布局,scrollview只能显示第一个view,pagecontroll显示正常。话不多说,代码如下:
这是显示正常的:
- (void)initUI {
pageNumbers = 2;
bounds = self.frame;
view1 = [UIView new];
[view1 setFrame:CGRectMake(0, 0, bounds.size.width, bounds.size.height)];
view1.backgroundColor = [UIColor greenColor];
view2 = [UIView new];
[view2 setFrame:CGRectMake(bounds.size.width, 0, bounds.size.width, bounds.size.height)];
view2.backgroundColor = [UIColor yellowColor];
scrollView = [UIScrollView new];
[scrollView setFrame:CGRectMake(0, 0, bounds.size.width, bounds.size.height)];
[self addSubview:scrollView];
[scrollView addSubview:view1];
[scrollView addSubview:view2];
[scrollView setContentSize:CGSizeMake(bounds.size.width * pageNumbers, bounds.size.height)];
[scrollView setPagingEnabled:YES];
[scrollView setBounces:NO];
[scrollView setShowsHorizontalScrollIndicator:NO];
scrollView.delegate = self;