美文网首页
UIScrollView + Masonry

UIScrollView + Masonry

作者: Smallwolf_JS | 来源:发表于2019-07-18 22:06 被阅读0次

    废话不多说直接上代码

    - (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);
        }];
    }
    

    相关文章

      网友评论

          本文标题:UIScrollView + Masonry

          本文链接:https://www.haomeiwen.com/subject/hjarlctx.html