以下介紹均為個人學習理解,如果錯誤歡迎及時批評指正。
知識點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];
}];