关于scrollview设置约束的一些坑与总结经验
2016-07-10 本文已影响272人
浩瀚海洋里的木头
首先,scrollView 需要知道自己的内容尺寸从而决定该怎么滑动
scrollView里面的控件我原本放在正常的代码区块里面用masony设置约束,会造成scrollView还没确定的contentsize,从而导致约束设置失败,所以在scrollView里面的控件约束设置在viewDidLayoutSubviews里面,这时候scrollView的frame已经确定好了
-(void)viewDidLayoutSubviews{
[super viewDidLayoutSubviews];
CGFloat scrollViewWidth = [UIScreen mainScreen].bounds.size.width;
[self.leftView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.scrollView);
make.top.equalTo(self.scrollView);
make.width.mas_equalTo(self.view.frame.size.width);
make.height.mas_equalTo(self.scrollView.frame.size.height);
}];
[self.rightView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.leftView.mas_right);
make.top.equalTo(self.scrollView);
make.width.mas_equalTo(self.view.frame.size.width);
make.height.mas_equalTo(self.scrollView.frame.size.height);
}];
self.scrollView.contentSize = CGSizeMake(scrollViewWidth*2,0);
if (self.banner.intValue == 0) {
self.picImageView.image = [UIImage imageNamed:@"illness_img_person.png"];
}else{
[self.picImageView sd_setImageWithURL:[NSURL URLWithString:self.imgName]];
}
// [self setupCollectionViewLayout];
self.nameLabel.text = self.doctorName;
self.picImageView.layer.cornerRadius = 40;
self.picImageView.layer.masksToBounds = YES;
}
}