backgroundView 為scrollview 全局定義了
代碼直接復(fù)制到項目里就可以看滾動效果 注釋是特別需要注意的
代碼有的空格需要自己加 這邊格式會自動對齊 我稍微改了改
中間控件隨便加 上下控件要加好 左右一定不要設(shè)置為scrollview的左右
- (void)setUI{
? ? backgroundView= [[UIScrollView alloc]init];
? ? [self.view addSubview:backgroundView];
? ? UIView*bottomView = [[UIViewalloc] init];//最底部view
? ? [backgroundView addSubview:bottomView];
? ? [backgroundView mas_makeConstraints:^(MASConstraintMaker *make) {//預(yù)設(shè)scrollView最底部控件約束!!!
? ? ? ? make.edges.equalTo(self.view);
? ? ? ? make.bottom.equalTo(bottomView.mas_top).offset(-103);
? ? }];
//? ? make.left.and.right.equalTo(self.view); 這里scrollView是垂直方向滾動岖免,所以設(shè)置第一個子視圖的左右約束于self.view(可以是別的view)的左右約束相等税课,切記不能設(shè)置成和scrollView的約束相等悼做。!!!
//? ? make.top.equalTo(self.scrollView); 最頂部的子視圖的top約束和scrollView相等治筒,切記不能設(shè)置為self.view需五,不然scrollView無法滾動。!!!
? ? UIImageView*topbagImage = [[UIImageView alloc]init];
? ? [backgroundView addSubview:topbagImage];
? ? [topbagImage mas_makeConstraints:^(MASConstraintMaker *make) {//scrollview頂部控件約束 設(shè)置左右須是self.view
? ? ? ? make.top.equalTo(backgroundView);
? ? ? ? make.left.right.equalTo(self.view);
? ? ? ? make.height.mas_equalTo(230);
? ? }];
? ? topbagImage.image= [UIImage imageNamed:@"bg_詳情頁"];
? ? UIImageView*headView = [[UIImageView alloc]init];
? ? [backgroundView addSubview:headView];
? ? [headView mas_makeConstraints:^(MASConstraintMaker*make) {
? ? ? ? make.bottom.equalTo(topbagImage);
? ? ? ? make.centerX.equalTo(topbagImage);
? ? ? ? make.width.height.mas_equalTo(66);
? ? }];
? ? headView.layer.cornerRadius=33;
? ? headView.layer.masksToBounds=YES;
? ? headView.image= [UIImage imageNamed:@"head"];
? ? [bottomView mas_makeConstraints:^(MASConstraintMaker *make) {//設(shè)置最底部view 距離上一個子view的約束 left和right必須設(shè)置為self.view;!7糜铡!
? ? ? ? make.top.equalTo(headView.mas_bottom).offset(800);
? ? ? ? make.left.right.equalTo(self.view);
? ? }];
}