关于scrollview设置约束的一些坑与总结经验

首先,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;
}

}



最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 1.badgeVaule气泡提示 2.git终端命令方法> pwd查看全部 >cd>ls >之后桌面找到文件夹内容...
    i得深刻方得S阅读 4,770评论 1 9
  • 前言 在iOS开发中,autolayout是一个很强大的东西,用好了,能让你事半功倍,用不好,各种蛋疼。不过aut...
    codingZero阅读 26,902评论 43 224
  • 发现 关注 消息 iOS 第三方库、插件、知名博客总结 作者大灰狼的小绵羊哥哥关注 2017.06.26 09:4...
    肇东周阅读 12,255评论 4 61
  • 我最想去地方莫过于厦门大学。它也是许多莘莘学子向往的地方。厦大校园依山伴海,背靠五老峰,与闽南古刹南普陀寺为邻,出...
    风铃儿风铃儿阅读 580评论 0 0
  • 已经不知道是第几次了,我看着你的背影在我的视线里消失。但我知道,这也许是最后一次了,因为,我将从此见不到你。看着你...
    鹤之舞阅读 181评论 0 0