您好!欢迎来到爱源码

爱源码

热门搜索: 抖音快手短视频下载   

砖石学习 <源码分享>

  • 时间:2022-07-07 01:21 编辑: 来源: 阅读:313
  • 扫一扫,手机访问
摘要:砖石学习 <源码分享>
现在iPhone屏幕越来越多,屏幕适配也越来越重要。砖石是为屏幕改编而生的三方框架。masonry basic API MAS _ make constraints()在mas_remakeConstraints()移除之前添加约束,添加新的约束mas_updateConstraints()升级约束,写哪个升级哪个,其他约束不变。equalTo()参数是对象类型,通常是视图对象或坐标系对象,如mas_width。mas_equalTo()的作用和上面一样,参数可以传递基本数据类型对象。可以理解为width()比上面的API更强大的表示宽度,比如表示视图的宽度,mas_width()用来获取宽度的值。 和上面的区别在于,一个表示一个坐标系对象,另一个用来获取坐标系对象的值。升级约束和布局-(void)updateconstraintsifneed。调用这个方法,如果有一个约束标记为需要重新排列,就立即重新排列。将在内部调用updateConstraints方法-(void)updateConstraints。这个方法将被重写,内部实现将设置自己的布局过程-(BOOL)needsUpdateConstraints。目前是否需要重新布局,会在内部判断当前是否有约束标记——(void)set needs update constraints标记需要重新布局。Masonry样本代码Masonry本质上封装了系统AutoLayout,里面包含了很多API,都是针对系统API封装了一两次。 typedefNS_OPTIONS(NSInteger,MASAttribute){ MASAttribute left = 1 & lt;& ltNSLayoutAttributeLeft,MASAttributeRight = 1 & lt& ltNSLayoutAttributeRight,MASAttributeTop = 1 & lt& ltNSLayoutAttributeTop,MASAttributeBottom = 1 & lt& ltNSLayoutAttributeBottom,MASAttributeLeading = 1 & lt& ltNSLayoutAttributeLeading,MASAttributeTrailing = 1 & lt& ltNSLayoutAttributeTrailing,MASAttributeWidth = 1 & lt& ltNSLayoutAttributeWidth,MASAttributeHeight = 1 & lt& ltNSLayoutAttributeHeight,MASAttributeCenterX = 1 & lt& ltNSLayoutAttributeCenterX,MASAttributeCenterY = 1 & lt& ltNSLayoutAttributeCenterY,MASAttributeBaseline = 1 & lt& ltNSLayoutAttributeBaseline,};常用方法设置内边距/* *设置yellow view和self.view的大小,内边距为10。 注意,根据UIView的坐标系,下面的右下方是颠倒的。 所以不能这样写,否则右下方向都会有问题。 make . edges . equal to(self . view). with . offset(10);除了下面示例中的offset()方法之外,对于不同的坐标系,还有centerOffset()、sizeOffset()和valueOffset()等方法。 */[self . yellow view mas_makeconstraints:^(masconstraintmaker*make){make.left.equalto(self.view).with.offset(10);make . top . equal to(self . view). with . offset(10);make . right . equal to(self . view). with . offset(-10);make . bottom . equal to(self . view). with . offset(-10);}];简化通过插页设置内边距的方式。//除了使用inserts()方法之外,下面的方法与上面的示例等效。 【自我。blueviewmas _ make constraintmaker:(masconstraintmaker * make){//不需要在底部和右侧写负号,insets方法中已经为我们做了逆运算。 make . edges . equal to(self . view). with . insets(UIEdgeInsetsMake(10,10,10,10));}];升级约束//设置greenView的中心和大小,这样就可以达到简单约束的目的【自我。greenview MAS _ make约束:(MAS constraint maker * make){ make . center . equal to(self . view);//这里通过mas_equalTo为size设置基本数据类型的参数,参数是CGSize的结构,make . size . MAS _ equal to(CGSizeMake(300,300));}];//为了更清楚的看到绑定变化的效果,显示两秒后升级绑定。 dispatch _ after(dispatch _ time(dispatch _ time _ now,(int64 _ t) (2。f * nsec _ per _ sec))、dispatch _ get _ main _ queue()、{//指定升级大小,其余约束保持不变。 【self . greenview mas_updateconstraints:^(masconstraintmaker*make){make.size.mas_equalto(cgsizemake(100,100));}];});约束大于或等于某个值[self。文本标签mas _ make约束:(masconstraint maker * make) {make。居中。等于(自我。查看);//将宽度设置为小于等于200 make . width . lesssanorequalto(@ 200);//将高度设置为大于等于10 make . height . greaterthanorequalto(@(10));}];Self.textLabel.text=@ "这是测试字符串。 您可以看到步骤1、2和3。第一步当然是上传照片。你应该上传一张最近的正面照片。 上传后,网站会自动识别你的脸。如果觉得识别不准确,也可以手动修改。 左边可以看到16个修改参数,最上面是整体修改,也可以根据自己的意愿修改一项。将鼠标放在选项上,右边的预览会显示相应的位置。 ";只要你想设置属性,TextLabel可以是self . text label . number of lines = 0;使用基本数据类型作为参数/* *如果你想使用基本数据类型作为参数,Masonry为我们提供了“mas_xx”格式的宏定义。 这些宏定义会将传入的基本数据类型转换为NSNumber类型,这个过程称为自动装箱。 “mas_xx”开头的宏定义都是由MASBoxValue()函数在内部实现的。 这样的宏定义有四个,分别是mas_equalTo()、mas_offset()和大于等于或小于等于四。 */[self . redview mas_makeconstraints:^(masconstraintmaker*make){make.center.equalto(self.view);make . width . MAS _ equal to(100);make . height . MAS _ equal to(100);}];set constraint priority/* * Masonry为我们提供了三种默认方法,分别是priorityLow()、priorityMedium()和priorityHigh(),对应不同的默认优先级。 除了这三种方法,我们还可以自定义priority的值,可以通过priority()方法来设置。 */[self . redview mas_makeconstraints:^(masconstraintmaker*make){make.center.equalto(self.view);make.width.equalTo(self.view)。priority low();make.width.mas_equalTo(20)。priority high();make.height.equalTo(self.view)。优先级(200);make.height.mas_equalTo(100)。优先级(1000);}];Masonry还帮我们定义了几个默认的优先级常数,对应不同的值,最大优先级值是1000。 staticonstmaslayoutpriority MASLayoutPriorityRequired = UILayoutPriorityRequired;staticonstmaslayoutpriority MASLayoutPriorityDefaultHigh = UILayoutPriorityDefaultHigh;staticonstmaslayoutpriority MASLayoutPriorityDefaultMedium = 500;staticonstmaslayoutpriority MASLayoutPriorityDefaultLow = UILayoutPriorityDefaultLow;staticonstmaslayoutpriority MASLayoutPriorityFittingSizeLevel = UILayoutPriorityFittingSizeLevel;设置绑定比率//设置当前绑定值乘以多少。例如,在本例中,redView的宽度是self.view的0.2倍 【self . red view mas_makeconstraints:^(masconstraintmaker*make){make.center.equalto(self.view】;make . height . MAS _ equal to(30);make.width.equalTo(self.view)。乘以(0.2);}];练习小的子视图等高/等宽练习/* *以下示例通过将数组传递给equalTo()方法,设置数组中子视图与当前make对应的视图之间的等高。 应该注意的是,当在下面的块中设置边距时,应该使用insets而不是offset。 因为用offset设置右下边距的时候,这两个值应该是负数,所以如果用offset统一设置的话会有问题。 */CG float padding = 10;ui view * red view =[[ui view alloc]init];red view . background color =[ui color red color];【self . view add subview:red view】;ui view * blue view =[[ui view alloc]init];blue view . background color =[ui color blue color];【self . view add subview:blue view】;ui view * yellow view =[[ui view alloc]init];yellow view . background color =[ui color yellow color];【self . view add subview:yellow view】;/* * * * * * * * *等高* * * * * * * * * * */[red view MAS _ make constraintmaker * make){ make . left . right . top . Equal to(self . view)。inserts(Uiedgeinsetsmake(make . bottom . equal to(blue view . MAS _ top))。offset(-padding);}];[mas_makeconstraints:^(masconstraintmaker*make){make.left.right.equalto(self.view).蓝景insets(UIEdgeInsetsMake(0,padding,0,padding));make . bottom . equal to(yellow view . MAS _ top)。offset(-padding);}];/* *关键是设置下面的make.height数组,通过它可以设置三视图高度相等。 例如剩余宽度等。,都差不多。 */[mas_makeconstraints:^(masconstraintmaker*make){make.left.right.bottom.equalto(self.view).黄景insets(UIEdgeInsetsMake(0,padding,padding,padding));make.height.equalTo(@[blueView,red view]);}];/* * * * * * * * *等宽* * * * * * * * */[red view MAS _ make constraintmaker * make){ make . top . left . bottom . Equal to(self . view)。inserts(uiedgeinsets make make . right . equal to(blue view . MAS _ left)。offset(-padding);}];[mas_makeconstraints:^(masconstraintmaker*make){make.top.bottom.equalto(self.view).蓝景insets(UIEdgeInsetsMake(padding,0,padding,0));make . right . equal to(yellow view . MAS _ left)。offset(-padding);}];[mas_makeconstraints:^(masconstraintmaker*make){make.top.bottom.right.equalto(self.view).黄景insets(UIEdgeInsetsMake(padding,0,padding,padding));make.width.equalTo(@[redView,blue view]);}];练习CGFloat padding=10用于等宽子视图的垂直居中;ui view * red view =[[ui view alloc]init];red view . background color =[ui color red color];【self . view add subview:red view】;ui view * blue view =[[ui view alloc]init];blue view . background color =[ui color blue color];【self . view add subview:blue view】;【红景mas_makeconstraints:^(masconstraintmaker*make){make.centery.equalto(self.view】;make.left.equalTo(self.view)。mas_offset(填充);make . right . equal to(blue view . MAS _ left)。MAS _ offset(-padding);//make . width . equal to(blue view);make . height . MAS _ equal to(150);}];【蓝景mas_makeconstraints:^(masconstraintmaker*make){make.centery.equalto(self.view】;make.right.equalTo(self.view)。MAS _ offset(-padding);make . width . equal to(red view);make . height . MAS _ equal to(150);}];作者:https://www.jianshu.com/p/587efafdd2b3浅浅罗瑜链接:来源:简书版权归作者所有。 商业转载请联系作者授权,非商业转载请注明出处。


  • 全部评论(0)
资讯详情页最新发布上方横幅
最新发布的资讯信息
【域名/主机/服务器|】qq邮箱提醒在哪里打开(2024-06-04 18:58)
【技术支持|常见问题】1556原创ng8文章搜索页面不齐(2024-05-01 14:43)
【技术支持|常见问题】1502企业站群-多域名跳转-多模板切换(2024-04-09 12:19)
【技术支持|常见问题】1126完美滑屏版视频只能显示10个(2024-03-29 13:37)
【技术支持|常见问题】响应式自适应代码(2024-03-24 14:23)
【技术支持|常见问题】1126完美滑屏版百度未授权使用地图api怎么办(2024-03-15 07:21)
【技术支持|常见问题】如何集成阿里通信短信接口(2024-02-19 21:48)
【技术支持|常见问题】算命网微信支付宝产品名称年份在哪修改?风水姻缘合婚配对_公司起名占卜八字算命算财运查吉凶源码(2024-01-07 12:27)
【域名/主机/服务器|】帝国CMS安装(2023-08-20 11:31)
【技术支持|常见问题】通过HTTPs测试Mozilla DNS {免费源码}(2022-11-04 10:37)

联系我们
Q Q:375457086
Q Q:526665408
电话:0755-84666665
微信:15999668636
联系客服
企业客服1 企业客服2 联系客服
86-755-84666665
手机版
手机版
扫一扫进手机版
返回顶部