需要使用UIScrollView实现3页滑屏
得纯代码实现 使用了Masonry适配
需要注意的是
scrollView与3页视图之间还需要一个View
- (void)viewDidLoad
{
[super viewDidLoad];
UIScrollView *scrollView = UIScrollView.new;
scrollView.backgroundColor = [UIColor redColor];
[self.view addSubview:scrollView];
[scrollView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(self.view);
}];
UIView *contentView = UIView.new;
contentView.backgroundColor = [UIColor blackColor];
[scrollView addSubview:contentView];
[contentView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(scrollView);
make.height.equalTo(scrollView);
}];
UIView *view1 = UIView.new;
view1.backgroundColor = [UIColor greenColor];
[contentView addSubview:view1];
[view1 mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(@0.0);
make.left.equalTo(@0.0);
make.width.equalTo(scrollView.mas_width);
make.height.equalTo(scrollView.mas_height);
}];
UIView *view2 = UIView.new;
view2.backgroundColor = [UIColor yellowColor];
[contentView addSubview:view2];
[view2 mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(@0.0);
make.left.equalTo(view1.mas_right);
make.width.equalTo(scrollView.mas_width);
make.height.equalTo(scrollView.mas_height);
}];
UIView *view3 = UIView.new;
view3.backgroundColor = [UIColor purpleColor];
[contentView addSubview:view3];
[view3 mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(@0.0);
make.left.equalTo(view2.mas_right);
make.width.equalTo(scrollView.mas_width);
make.height.equalTo(scrollView.mas_height);
}];
[contentView mas_makeConstraints:^(MASConstraintMaker *make) {
make.right.equalTo(view3.mas_right);
}];
}

Jietu20190610-110744.jpg

Jietu20190610-110712.jpg