Masonry

作者: Jimsir | 来源:发表于2016-07-09 16:37 被阅读108次

    以下介绍均为个人学习理解,如果错误欢迎及时批评指正。

    知识点1:

    // auto-boxing macros allow you to simply use scalars and structs, they will be wrapped automatically

    [orangeView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.equalTo(CGPointMake(0, 50));//这里()里面的值代表相对于父视图的位置
        make.size.equalTo(CGSizeMake(200, 100));//这里的()里面的值代表自身的size 
    }];
    

    知识点2:

    [view mas_makeConstraints:^(MASConstraintMaker *make) {
       make.edges.equalTo(lastView).insets(UIEdgeInsetsMake(5, 10, 15, 20));//edges代表距离别的视图的边缘距离,insets代表偏移量
    

    }];

    知识点3:

       // Layout top and bottom views to each take up half of the window
      [self.topView  mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.and.top.equalTo(self);//这里的left,right,top代表与self一致
    }];      
    

    知识点4:

    // Inner views are configured for aspect fit with ratio of 3:1
    [self.topView addSubview:self.topInnerView] [self.topInnerViewmas_makeConstraints:^(MASConstraintMaker *make) { make.width.equalTo(self.topInnerView.mas_height).multipliedBy(3);//代表宽度是自身高度的3:1 make.width.and.height.lessThanOrEqualTo(self.topView);//自身的宽高小于等于self.topview的宽高 make.width.and.height.equalTo(self.topView).with.priorityLow();//自身的宽高等于self.topView的宽高,但是优先级低 make.center.equalTo(self.topView);//自身的中心等于self.topView的中心 }];
    知识点5:

    //you can attach debug keys to views like so:
    //    greenView.mas_key = @"greenView";//相当于给greenView的所有约束都提供了一个键
    //    redView.mas_key = @"redView";
    //    blueView.mas_key = @"blueView";  
    //    superview.mas_key = @"superview";
    //  调试约束的时候用到的Key
    //OR you can attach keys automagically like so:
      MASAttachKeys(greenView, redView, blueView, superview) ;make.height.greaterThanOrEqualTo(@5000).key(@"ConstantConstraint");//给单独的约束添加key
    

    知识点6:

    [self.growingButton updateConstraints:^(MASConstraintMaker *make) { make.center.equalTo(self); make.width.equalTo(@(self.buttonSize.width)).priorityLow();//equalTo后面接NSNumber类型的数据(我试过用Integer类型的也可以) make.height.equalTo(@(self.buttonSize.height)).priorityLow(); make.width.lessThanOrEqualTo(self); make.height.lessThanOrEqualTo(self); }];
    知识点7:
    添加动画
    // tell constraints they need updating
    [self setNeedsUpdateConstraints];

    // update constraints now so we can animate the change
    [self updateConstraintsIfNeeded];
    
    [UIView animateWithDuration:0.4 animations:^{
        [self layoutIfNeeded];
    }];

    相关文章

      网友评论

        本文标题:Masonry

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