废话不多说直接上代码
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
[self.view addSubview:self.scrollView];
[self setupSub];
[self layoutSubviewSnapKit];
}
- (UIScrollView *)scrollView{
if (!_scrollView) {
_scrollView = [[UIScrollView alloc]init];
_scrollView.backgroundColor = [UIColor purpleColor];
_scrollView.pagingEnabled = YES;
_scrollView.showsVerticalScrollIndicator = NO;
// _scrollView.directionalLockEnabled = YES;
_scrollView.bounces = NO;
}
return _scrollView;
}
- (void)setupSub{
self.leftVC = [[leftViewController alloc]init];
self.rightVC = [[rightViewController alloc]init];
[self addChildViewController:self.leftVC];
[self addChildViewController:self.rightVC];
[self.scrollView addSubview:self.leftVC.view];
[self.scrollView addSubview:self.rightVC.view];
}
- (void)layoutSubviewSnapKit{
[self.leftVC.view mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.bottom.mas_equalTo(self.view);
make.width.mas_equalTo(kScreenWidth);
make.left.mas_equalTo(self.scrollView);
}];
[self.rightVC.view mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.bottom.mas_equalTo(self.view);
make.width.mas_equalTo(kScreenWidth);
make.left.mas_equalTo(self.leftVC.view.mas_right);
}];
[self.scrollView mas_updateConstraints:^(MASConstraintMaker *make) {
make.edges.mas_equalTo(self.view);
make.right.mas_equalTo(self.rightVC.view);
}];
}
网友评论