UIView高度约束的三种方法(这里只是讨论equalTo(),这个block执行的结果)
make.height.equalTo(@20); (@20可认为是一个NSValue代表)
make.height.equalTo(self.view);
make.height.equalTo(self.view.mas_height);
执行equalTo() block,会有以下函数调用

针对 self.secondViewAttribute = attribute讨论,Masonry重写了setter方法

这就是为什么equalTo() block支持这三种方式
_secondViewAttribute 是一个 MASViewAttribute实例对象,该类仅对UIView 和 NSLayoutAttribute进行包装;
第一种:
make.height.equalTo(@20),进行了类型判断+Typecode判断,对不同的属性进行不同的处理

第二种: make.height.equalTo(self.view)
依赖firViewAttribute提供的layoutAttribute 生成一个MASViewAttribute对象
第三种:make.height.equalTo(self.view.mas_height);
因为self.view.mas_height 是Masonry提供的类别方法,直接生成了一个MASViewAttribute

网友评论