Masonry源碼分析三:鏈?zhǔn)秸Z法分析和一些其他細(xì)節(jié)

本章大致描述一下Masonry是如何支持鏈?zhǔn)秸Z法的亿鲜,并且對框架的其他一些文件做一些描述

第一部分 了解一下鏈?zhǔn)秸Z法是如何實(shí)現(xiàn)的###

實(shí)際上前面兩篇文章已經(jīng)講述的差不多了寇漫,如果看過源碼例嘱,應(yīng)該就會很輕松的知道,Masonry是如何支持鏈?zhǔn)秸Z法的結(jié)構(gòu)。

還是拿一個(gè)例子的講解一下吧,(下方代碼已刪除不甚相關(guān)的代碼)

    make.top.left究竟發(fā)生了什么际看?
    
    我們知道m(xù)ake.top返回的是MASConstraint對象,更確切的說是MASViewConstraint對象矢否,
    上篇文章中我們知道仲闽,對MASConstraint調(diào)用top、left等僵朗,會返回一個(gè)MASCompositeConstraint對象赖欣;
    這個(gè)對象,會包含一個(gè)數(shù)組验庙,在這個(gè)例子中存放的就是layoutAttribute分別為top和left的
    兩個(gè)MASViewConstraint對象顶吮。
    
    1、MASConstraint的left方法:
    
    - (MASConstraint *)left {
        return [self addConstraintWithLayoutAttribute:NSLayoutAttributeLeft];
    }
    它會跳轉(zhuǎn)到MASViewConstraint的addConstraintWithLayout...方法
--------------------------------------------    
    2粪薛、MASViewConstraint的addConstraintWithLayout...方法

    - (MASConstraint *)addConstraintWithLayoutAttribute:(NSLayoutAttribute)layoutAttribute {
        return [self.delegate constraint:self addConstraintWithLayoutAttribute:layoutAttribute];
    }
    它會調(diào)用delegate的constraint...delegate就是MASConstraintMaker悴了,來看看吧
--------------------------------------------
    3、MASConstraintMaker的代理方法
    
    - (MASConstraint *)constraint:(MASConstraint *)constraint addConstraintWithLayoutAttribute:(NSLayoutAttribute)layoutAttribute {
            MASCompositeConstraint *compositeConstraint = [[MASCompositeConstraint alloc] initWithChildren:children];
            [self constraint:constraint shouldBeReplacedWithConstraint:compositeConstraint];
            return compositeConstraint;
    }
    

第二部分 一些Category###



??1汗菜、NSArray (MASAdditions)

array內(nèi)部是view让禀,遍歷array,逐一對view調(diào)用這些方法

    - (NSArray *)mas_makeConstraints:(void (^)(MASConstraintMaker *make))block;
    - (NSArray *)mas_updateConstraints:(void (^)(MASConstraintMaker *make))block;
    - (NSArray *)mas_remakeConstraints:(void (^)(MASConstraintMaker *make))block;

2陨界、View+MASAdditions

我們平時(shí)巡揍,也可以對view調(diào)用一些方法例如:

    @property (nonatomic, strong, readonly) MASViewAttribute *mas_left;
    @property (nonatomic, strong, readonly) MASViewAttribute *mas_top;
    @property (nonatomic, strong, readonly) MASViewAttribute *mas_right;
    @property (nonatomic, strong, readonly) MASViewAttribute *mas_bottom;
    @property (nonatomic, strong, readonly) MASViewAttribute *mas_leading;
    @property (nonatomic, strong, readonly) MASViewAttribute *mas_trailing;
    @property (nonatomic, strong, readonly) MASViewAttribute *mas_width;
    @property (nonatomic, strong, readonly) MASViewAttribute *mas_height;
    @property (nonatomic, strong, readonly) MASViewAttribute *mas_centerX;
    @property (nonatomic, strong, readonly) MASViewAttribute *mas_centerY;
    @property (nonatomic, strong, readonly) MASViewAttribute *mas_baseline;
    

可以看到,返回的是MASViewAttribute對象

剩下的就是比較簡單的mas_makeConstraint...

3菌瘪、ViewController+MASAdditions

    @property (nonatomic, strong, readonly) MASViewAttribute *mas_topLayoutGuide;
    @property (nonatomic, strong, readonly) MASViewAttribute *mas_bottomLayoutGuide;
    @property (nonatomic, strong, readonly) MASViewAttribute *mas_topLayoutGuideTop;
    @property (nonatomic, strong, readonly) MASViewAttribute *mas_topLayoutGuideBottom;
    @property (nonatomic, strong, readonly) MASViewAttribute *mas_bottomLayoutGuideTop;
    @property (nonatomic, strong, readonly) MASViewAttribute *mas_bottomLayoutGuideBottom;

這些就是對齊self.view的頂部導(dǎo)航欄和底步tabbar的頂部了腮敌,底部之類的

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個(gè)濱河市俏扩,隨后出現(xiàn)的幾起案子糜工,更是在濱河造成了極大的恐慌,老刑警劉巖录淡,帶你破解...
    沈念sama閱讀 216,544評論 6 501
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件捌木,死亡現(xiàn)場離奇詭異,居然都是意外死亡嫉戚,警方通過查閱死者的電腦和手機(jī)刨裆,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,430評論 3 392
  • 文/潘曉璐 我一進(jìn)店門澈圈,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人帆啃,你說我怎么就攤上這事瞬女。” “怎么了努潘?”我有些...
    開封第一講書人閱讀 162,764評論 0 353
  • 文/不壞的土叔 我叫張陵诽偷,是天一觀的道長。 經(jīng)常有香客問我疯坤,道長报慕,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 58,193評論 1 292
  • 正文 為了忘掉前任压怠,我火速辦了婚禮卖子,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘刑峡。我一直安慰自己,他們只是感情好玄柠,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,216評論 6 388
  • 文/花漫 我一把揭開白布突梦。 她就那樣靜靜地躺著,像睡著了一般羽利。 火紅的嫁衣襯著肌膚如雪宫患。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 51,182評論 1 299
  • 那天这弧,我揣著相機(jī)與錄音娃闲,去河邊找鬼。 笑死匾浪,一個(gè)胖子當(dāng)著我的面吹牛皇帮,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播蛋辈,決...
    沈念sama閱讀 40,063評論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼属拾,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了冷溶?” 一聲冷哼從身側(cè)響起渐白,我...
    開封第一講書人閱讀 38,917評論 0 274
  • 序言:老撾萬榮一對情侶失蹤,失蹤者是張志新(化名)和其女友劉穎逞频,沒想到半個(gè)月后纯衍,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 45,329評論 1 310
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡苗胀,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,543評論 2 332
  • 正文 我和宋清朗相戀三年襟诸,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了瓦堵。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點(diǎn)故事閱讀 39,722評論 1 348
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡励堡,死狀恐怖谷丸,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情应结,我是刑警寧澤刨疼,帶...
    沈念sama閱讀 35,425評論 5 343
  • 正文 年R本政府宣布,位于F島的核電站鹅龄,受9級特大地震影響揩慕,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜扮休,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,019評論 3 326
  • 文/蒙蒙 一迎卤、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧玷坠,春花似錦蜗搔、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,671評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至兄渺,卻和暖如春缝龄,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背挂谍。 一陣腳步聲響...
    開封第一講書人閱讀 32,825評論 1 269
  • 我被黑心中介騙來泰國打工叔壤, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留,地道東北人口叙。 一個(gè)月前我還...
    沈念sama閱讀 47,729評論 2 368
  • 正文 我出身青樓炼绘,卻偏偏與公主長得像,于是被迫代替她去往敵國和親妄田。 傳聞我的和親對象是個(gè)殘疾皇子饭望,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 44,614評論 2 353

推薦閱讀更多精彩內(nèi)容