Masonry对UIScrollerView添加约束

UIView* contentView = UIView.new;

    [self.scrollView addSubview:contentView];

    

    [contentView makeConstraints:^(MASConstraintMaker *make) {

        make.edges.equalTo(self.scrollView);

        make.width.equalTo(self.scrollView);

    }];

    

    UIView *lastView;

    CGFloat height = 25;

    

    for (int i = 0; i < 10; i++) {

        UIView *view = UIView.new;

        view.backgroundColor = [self randomColor];

        [contentView addSubview:view];

        

        UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(singleTap:)];

        [view addGestureRecognizer:singleTap];

        

        [view mas_makeConstraints:^(MASConstraintMaker *make) {

            make.top.equalTo(lastView ? lastView.bottom : @0);

            make.left.equalTo(@0);

            make.width.equalTo(contentView.width);

            make.height.equalTo(@(height));

        }];

        

        height += 25;

        lastView = view;

    }

    

    [contentView makeConstraints:^(MASConstraintMaker *make) {

        make.bottom.equalTo(lastView.bottom);

    }];

posted @ 2016-04-15 16:40  YouNeedCourage  阅读(508)  评论(0编辑  收藏  举报