美文网首页
iOS开发Masonry自动布局注意事项

iOS开发Masonry自动布局注意事项

作者: 我的心都有自己喜欢做个爱豆一样 | 来源:发表于2018-08-01 16:25 被阅读0次

Masonryde 的优点很多,就不多说了,但是在我刚开始使用的时候出现过一些问题,在这里写出来,防止忘记.

第一个就是一定要添加到view上,就是先使用addSubview,不然的话,肯定会崩溃;

第二个就是导航条不要使用Masonry.

第三个就是with和and,内部是把self返回,没有实际意义

- (MASConstraint *)with {

    return self;

}

- (MASConstraint *)and {

    return self;

}


使用心得(根据GitHub上的demo写的)

一、可以传数组

   make.height.equalTo(@[greenView, blueView]);//can pass array of views

效果是高度和数组里的空间相等

二、更新约束

// this is Apple's recommended place for adding/updating constraints

-  (void)updateConstraints;

三、重新创建约束

remakeConstraints

四、内边距

        make.edges.equalTo(lastView).insets(UIEdgeInsetsMake(5,10,15,20));

五、TableView的自动布局

很简单,  

    [self.contentView addSubview:self.bgView];

  [self.bgView mas_makeConstraints:^(MASConstraintMaker *make) {

        make.top.equalTo(self.contentView).offset(10);

//        make.height.mas_equalTo(120);

        make.left.mas_equalTo(20);

        make.right.mas_equalTo(-20);

        make.bottom.mas_equalTo(0);

    }];

label换行就行,tableview的方法里不要调用

//- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {

//    UITableViewCell *cell = [self tableView:self.TV cellForRowAtIndexPath:indexPath];

//    return cell.frame.size.height;

//}

不用调用就好

//    self.branchTV.estimatedRowHeight = 130;

//    self.branchTV.rowHeight = UITableViewAutomaticDimension;

这两个方法也可以不写

六、成比例

三分之一

 make.height.equalTo(self.bottomInnerView.mas_width).multipliedBy(3);

multipliedBy(3)

相关文章

  • 适配

    Masonry iOS自动布局框架-Masonry详解

  • iOS 常用布局方式之Masonry

    级别: ★☆☆☆☆标签:「iOS Masonry」「iOS 自动布局」「Masonry」作者: Xs·H审校: ...

  • Masonry布局框架简单的介绍和使用。

    Masonry(自动布局)的基本使用 Masonry的基本介绍 在iOS开发中,为了满足开发者对苹果手机屏幕进行一...

  • Masonry源码分析与链式编程

    在ios开发中,Masonry是最常用的第三方开发布局框架。Masonry是基于自动布局技术实现的,所以说Maso...

  • Third Party

    A:推荐使用 B:修改使用 C:参考使用 自动布局Masonry(A)iOS自动布局框架-Masonry详解SDA...

  • App架构方方面面

    布局 揭秘 iOS 布局 Masonry源码解析 自动布局&绝对布局autolayoutautolayout 动画...

  • swift中Masonry的布局

    iOS SnapKit自动布局使用详解(Swift版Masonry) 对于自动布局: 我们在 StoryBoard...

  • iOS开发Masonry自动布局注意事项

    Masonryde 的优点很多,就不多说了,但是在我刚开始使用的时候出现过一些问题,在这里写出来,防止忘记. 第一...

  • Masonry分析

    iOS 源代码分析----Masonry Masonry是OC自动布局的框架,简化了AutoLayout的写法。 ...

  • GitHub 收藏

    iOS Objective-C Masonry 自动布局库。Harness the power of AutoLa...

网友评论

      本文标题:iOS开发Masonry自动布局注意事项

      本文链接:https://www.haomeiwen.com/subject/alylvftx.html