如題,今天的任務是Nasonry介紹與使用實踐:快速上手Autolayout & 本身App項目的適配 & 遇到的問題及解決方法。佈局
Tips: .h與.m文件之間的切換快捷鍵 control + command + 上下鍵ui
Tips:如何在Xib中設置Button的屬性(圓角以及背景顏色)。Inspector -- User Defined Runtime Attributes -- layer.cornerRadius & Number & 10spa
9月14號更新--好吧,上週五的任務成功推遲到了今天,今天我們來會會它。.net
//mas_makeConstraints 只負責新增約束 Autolayout不能同時存在兩條針對於同一對象的約束 不然會報錯 - (NSArray *)mas_makeConstraints:(void(^)(MASConstraintMaker *make))block; //mas_remakeConstraints 則會清除以前的全部約束 僅保留最新的約束 - (NSArray *)mas_updateConstraints:(void(^)(MASConstraintMaker *make))block; //mas_updateConstraints 針對上面的狀況 會更新在block中出現的約束 不會致使出現兩個相同約束的狀況 - (NSArray *)mas_remakeConstraints:(void(^)(MASConstraintMaker *make))block;
首先是如何在項目中引用第三方庫的文件。即便用cocoaPods import導入時沒有提示的解決辦法:ssr
選擇target--> Building Settings-->User Header Search Paths -->在後面的空白處點擊。左側的寫入 $(PODS_ROOT) -- >後面的選擇rucursive。便可。code
好了,能夠調用了。對象
問了下大神,技能get時間。blog
好比說我若是想把這張圖片放在sele.view的中心,而後距離top50像素處,那麼代碼應該這麼寫。圖片
UIImageView *heads = [[UIImageView alloc] init]; heads.layer.masksToBounds = YES; heads.layer.cornerRadius = 27;//圓角半徑? [heads setImage:[UIImage imageNamed:@"user_head"]]; [self.view addSubview:heads]; [heads mas_makeConstraints:^(MASConstraintMaker *make){ make.top.equalTo(self.view).with.offset(30); make.centerX.equalTo(self.view); }];
這裏須要注意的是,自動佈局是相對於superView和兄弟view的,不能相對本身來佈局ip
因此代碼中括號裏面的是self.view,而不是heads。
---2015-09-15更新
上面所說的三種方法,昨天只用到了其中一種,即mas_makeConstraints。
估計本身只摸索着更表面的東西。上一個例子吧。
[loginButton mas_makeConstraints:^(MASConstraintMaker *make){ make.left.right.and.width.equalTo(self.view); make.top.equalTo(centerLabel.mas_bottom).with.offset(30); make.height.equalTo(@50); }];
像這種特別簡單,只須要記住一點,Masonry實現的autolayout這種佈局方式是相對於superView以及它的兄弟view的,千萬不能想對本身來佈局。