Masonry2个小技巧
2015-08-19 20:59
183 查看
获取真实frame
在不用Masonry时,frame在创建UIView时就已经确定,例如:CGRect frame = CGRectMake(0, 0, 375, 200); UIView *view = [[UIView alloc] initWithFrame:frame];
或者
UIView *view = [[UIView alloc] init]; view.frame = CGRectMake(0, 0, 375, 200);
但是使用Masonry时,坐标是根据约束计算得到的。在init方法里,view的frame是(0, 0, 0, 0),这不是view的真实frame。有时候会遇到问题,比如希望给view加一个底部的border
[self addOneSidedBorderWithFrame:CGRectMake(0, self.frame.size.height-height, self.frame.size.width, height) andColor:color];
所以,需要能够获取到view的真实frame,正确的时机应该是在layoutSubviews方法里,因为这时候应该开始layout subviews,Masonry已经计算出了真实的frame
-(void) layoutSubviews { [super layoutSubviews]; [uploadArea addBottomBorderWithHeight:1.f andColor:[ColorUtility basicGrayLineColor]]; [myUploadArea addBottomBorderWithHeight:1.f andColor:[ColorUtility basicGrayLineColor]]; }
实现动画效果
用以下的代码可以配合Masonry实现动画[switchBar mas_remakeConstraints:^(MASConstraintMaker *make) { make.right.equalTo(@0); make.bottom.equalTo(@0); make.width.equalTo(toupiaoBtn); make.height.equalTo(@2); }]; [UIView animateWithDuration:0.3 delay:0.0 options:UIViewAnimationOptionCurveLinear animations:^{ [switchBar layoutIfNeeded]; } completion:nil];
相关文章推荐
- 面试准备
- js学习阶段总结
- 14莫比乌斯反演模板
- apache wicket 7.X让html回归webapp目录下
- 容己容人容事,从容一生
- 第3章 线性表
- LeetCode(67) Add Binary
- 减治法
- LeetCode(67) Add Binary
- Angular 常用ng指令详解
- Realtek瑞昱首个官方Win10通用网卡驱动发布下载(支持32位和64位)
- zoj Count the Colors 1610 (数组模拟&&线段树)好题
- lua 可变参数
- Java知识点总结1
- 详略。。设计模式2——单例变形(多例).。。。studying
- Java知识点总结1
- 一个servlet处理多个请求,地址字符串怎么处理呢
- 博客已搬家至 hate13.com
- 通过try/catch block载入文件
- C++多线程学习:生产者消费者问题