masnory方法笔记

在使用masnory适配的时候,有些方法记不住,特此笔记记录。

1、居中设置
垂直居中:make.centerY.mas_equalTo(self.window.mas_centerY)
水平居中:make.centerX.mas_equalTo(self.window.mas_centerX)
全屏居中:make.center.equalTo(self.window)
2、边界设置
上边界:make.top.equalTo(self.window).with.offset(15.0)
左边界:make.left.equalTo(self.window).with.offset(15.0)
下边界:make.bottom.equalTo(self.window).with.offset(-15.0)
右边界:make.right.equalTo(self.window).with.offset(-15.0)
或:
上边界:make.top.mas_equalTo(15.0)
左边界:make.left.mas_equalTo(15.0)
下边界:make.bottom.mas_equalTo(-15.0)
右边界:make.right.mas_equalTo(-15.0)
或:
上边界、左边界:make.top.left.mas_equalTo(15.0)
下边界、右边界:make.bottom.right.mas_equalTo(-15.0)
或:make.top.left.bottom.and.right.equalTo(self.window).with.insets(UIEdgeInsetsMake(15.0,15.0,15.0,15.0))
或:make.edges.equalTo(self.window).with.insets(UIEdgeInsetsMake(15.0,15.0,15.0,15.0))
与另一个视图的边界间距设置
与另一个视图右部边界间距:make.right.mas_equalTo(currentView.mas_left).offset(10.0);
与另一个视图底部边界间距:make.top.mas_equalTo(currentView.mas_bottom).offset(10.0);
3、倍数设置
设置宽度为self.view的一半,multipliedBy是倍数的意思,也就是,使宽度等于self.view宽度的0.5倍
make.width.equalTo(self.view.mas_width).multipliedBy(0.5);
设置高度为self.view高度的一半
make.height.equalTo(self.view.mas_height).multipliedBy(0.5);
4、大小设置
宽:
make.width.equalTo(self.view.mas_width).multipliedBy(0.5);
或:make.width. mas_equalTo(320.0).multipliedBy(0.5);
或:make.width. mas_equalTo(160.0);
高:make.height.equalTo(self.view.mas_height).multipliedBy(0.5);
或:make.height. mas_equalTo(320.0).multipliedBy(0.5);
或:make.height. mas_equalTo(160.0);
size:make.size. mas_equalTo(CGSizeMake(300.0,50.0));
或:make.size.equalTo(view);
或:make.size.mas_equalTo(CGSizeMake(150.0,50.0)).multipliedBy(0.5);
4、将若干view等宽布局于容器containerView中
-(void)makeEqualWidthViews:(NSArray *)views inView:(UIView *)containerView LRpadding:(CGFloat)LRpadding viewPadding :(CGFloat)viewPadding
{
    UIView *lastView;
    for (UIView *view in views) {
        [containerView addSubview:view];
        if (lastView) {
            [view mas_makeConstraints:^(MASConstraintMaker *make) {
                make.top.bottom.equalTo(containerView);
                make.left.equalTo(lastView.mas_right).offset(viewPadding);
                make.width.equalTo(lastView);
            }];
        }else
        {
            [view mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.equalTo(containerView).offset(LRpadding);
                make.top.bottom.equalTo(containerView);
            }];
        }
        lastView=view;
    }
    [lastView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(containerView).offset(-LRpadding);
    }];
}
5、实现n宫格布局

布局说明
demo

6、移除约束重新布局

remake会将之前的全部移除,然后重新添加

// remake会将之前的全部移除,然后重新添加
  [self.growingButton mas_remakeConstraints:^(MASConstraintMaker *make) {
    make.top.mas_equalTo(0);
    make.left.right.mas_equalTo(0);
  
  }];
// 告诉self.view约束需要更新
  [self.view setNeedsUpdateConstraints];
  // 调用此方法告诉self.view检测是否需要更新约束,若需要则更新,下面添加动画效果才起作用
  [self.view updateConstraintsIfNeeded];

你可能感兴趣的:(masnory方法笔记)