美文网首页
iOS Masonry使用注意事项

iOS Masonry使用注意事项

作者: 邓布利多教授 | 来源:发表于2019-07-24 14:28 被阅读0次

需要先调用addsubview方法把yourView添加到父视图上。

1、添加约束

  • 使用 mas_makeConstraints
[self.yourView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(100);
        make.height.mas_equalTo(30);
        make.left.mas_equalTo(20);
        make.right.mas_equalTo(-20);
}];

2、移除之前的所有约束,并使用block里面的新约束重新布局

  • 使用 mas_remakeConstraints
[self.yourView mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(200);
        make.height.mas_equalTo(50);
        make.left.mas_equalTo(20);
        make.right.mas_equalTo(-20);
}];

3、更新约束

  • 使用 mas_updateConstraints
[self.yourView mas_updateConstraints:^(MASConstraintMaker *make) {
       make.top.mas_equalTo(400);
}];

4、简易动画

  • 使用 mas_updateConstraints
  • 如果yourView需要添加动画,必须执行父视图的layoutIfNeeded方法,因为视图动画frame的变动是相对父视图的,所以父视图需要执行layoutIfNeed才会重新布局对应的UI。
  • 如果用yourView执行layoutIfNeed只会重新布局,不会产生动画。
  • 可以写成[self.view layoutIfNeeded];或者[self.yourView.superview layoutIfNeeded];
[UIView animateWithDuration:0.5 animations:^{
            
       [self.yourView mas_updateConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(600);
       }];
       [self.view layoutIfNeeded];
            
}];

5、全剧终

相关文章

  • iOS - Masonry使用中的一些整理

    [置顶]iOS - Masonry使用中的一些整理 标签:iOS资源大全iOS常用方法iOS学习资料Masonry...

  • Third Party

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

  • iOS Masonry使用注意事项

    需要先调用addsubview方法把yourView添加到父视图上。 1、添加约束 使用 mas_makeCons...

  • YKAutolayout --- Make Masonry Ea

    项目Github地址 YKAutolayout Masonry 的 使用 做过iOS的对Masonry这个库应该都...

  • Masonry使用总结

    Masonry使用总结 一、Masonry简介 Masonry是一个轻量级的布局框架,适用于iOS以及OS X。它...

  • Masonry使用

    一、使用Maaonry注意事项 1.在使用Masonry添加约束之前,需要在addSubview之后才能使用,否则...

  • Masonry使用注意事项

    1、Masonry使用注意事项用mas_makeConstraints的那个view需要在addSubview之后...

  • Masonry

    Masonry介绍与使用实践 - iOS移动开发周报 - 推酷

  • Masonry源码分析

    Masonry是iOS在控件布局中经常使用的一个轻量级框架,Masonry让NSLayoutConstraint使...

  • iOS开发之Masonry框架-源码解析

    Masonry是iOS在控件布局中经常使用的一个轻量级框架。Masonry让NSLayoutConstraint使...

网友评论

      本文标题:iOS Masonry使用注意事项

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