// Created by xxzx on 2018/11/23.
// Copyright © 2018 xxzx. All rights reserved.
#import "ViewController.h"
@interface ViewController ()
@property (nonatomic, strong) UIScrollView *scrollView;
@property (nonatomic, strong) UIView *contentView;
@property (nonatomic, strong) UIView *oneView;
@property (nonatomic, strong) UIView *twoView;
@property (nonatomic, strong) UIView *threeView;
@implementation ViewController
[self.view addSubview:self.scrollView];
[self.scrollView addSubview:self.contentView];
[self.contentView addSubview:self.oneView];
[self.contentView addSubview:self.twoView];
[self.contentView addSubview:self.threeView];
- (void)viewDidLayoutSubviews {
[super viewDidLayoutSubviews];
[self.scrollView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(self.view);
[self.contentView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(self.scrollView);
make.width.equalTo(self.scrollView);
// make.height.greaterThanOrEqualTo(@0.0f);
[self.oneView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.contentView).offset(30);
make.left.equalTo(self.contentView);
make.width.mas_equalTo(200);
make.height.mas_equalTo(300);
[self.twoView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.oneView.mas_bottom).offset(50);
make.right.equalTo(self.contentView);
make.width.mas_equalTo(400);
make.height.mas_equalTo(500);
[self.threeView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.twoView.mas_bottom).offset(70);
make.left.right.equalTo(self.contentView);
make.height.mas_equalTo(300);
// 最后设置最后一个view的与参照容器view的约束
[self.contentView mas_makeConstraints:^(MASConstraintMaker *make) {
make.bottom.equalTo(self.threeView.mas_bottom).offset(-10);
- (UIScrollView *)scrollView {
if (_scrollView == nil) {
_scrollView = [[UIScrollView alloc] init];
_scrollView.backgroundColor = [UIColor grayColor];
- (UIView *)contentView {
if (_contentView == nil) {
_contentView = [[UIView alloc] init];
_contentView.backgroundColor = [UIColor yellowColor];
_oneView = [[UIView alloc] init];
_oneView.backgroundColor = [UIColor redColor];
_twoView = [[UIView alloc] init];
_twoView.backgroundColor = [UIColor blueColor];
_threeView = [[UIView alloc] init];
_threeView.backgroundColor = [UIColor greenColor];
