Masonry

以下介紹均為個人學習理解,如果錯誤歡迎及時批評指正。

知識點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];
}];
最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容

  • iOS_autoLayout_Masonry 概述 Masonry是一個輕量級的布局框架與更好的包裝AutoLay...
    指尖的跳動閱讀 1,185評論 1 4
  • (一)Masonry介紹 Masonry是一個輕量級的布局框架 擁有自己的描述語法 采用更優雅的鏈式語法封裝自動布...
    木易林1閱讀 2,371評論 0 3
  • Masonry是一個輕量級的布局框架,擁有自己的描述語法,采用更優雅的鏈式語法封裝自動布局,簡潔明了并具有高可讀性...
    3dcc6cf93bb5閱讀 1,798評論 0 1
  • [置頂]iOS - Masonry使用中的一些整理 標簽:iOS資源大全iOS常用方法iOS學習資料Masonry...
    DreamMakerSky閱讀 3,186評論 0 4
  • 4.1 我們從合肥7:00出發 11:20到婺源火車站接美姐 入住婺源清華 樸園度假村 休息后玩思溪、延村、彩虹橋...
    珂珂公子喵喵醬閱讀 350評論 0 0