使用Masonry布局不能立即获取到frame的问题
1. 先看下面这段代码:
[self.scrollView mas_makeConstraints:^(MASConstraintMaker *make) { make.edges.mas_equalTo(UIEdgeInsetsMake(0,0,0,0));}];NSLog(@"%@",self.scrollView);
打印结果:
<UIScrollView: 0x7fc461014000; frame = (0 0; 0 0);
2. 再看一段代码:
[self.scrollView mas_makeConstraints:^(MASConstraintMaker *make) { make.edges.mas_equalTo(UIEdgeInsetsMake(0,0,0,0));}];// 先调用superView的layoutIfNeeded方法再获取frame[self.view layoutIfNeeded];NSLog(@"%@",self.scrollView);
打印结果:
<UIScrollView: 0x7fc72d016000; frame = (0 0; 375 667);
所以我们可以通过调用layoutIfNeeded再去获取 frame
实际开发中遇到的问题
1.用Masonry布局一个 uilabel,然后用贝塞尔曲线绘制圆角,如果用贝塞尔曲线绘制圆角的方法写在awakeFromNib,layoutSubviews都是有问题的。因为在这些函数方法拿到的frame 都不是正确的,所以有问题。所以我们可以先给控件赋值后,再调layoutIfNeeded,再用贝塞尔曲线绘制圆角
self.typeTipLabel.text = @"";
[self layoutIfNeeded];
[self.typeTipLabel setCornerWithCornerRadii:CGSizeMake(5, 5) byRoundingCorners:UIRectCornerBottomLeft];
2.用Masonry布局一个 uiview ,然后设置阴影也没有效果。也要先调layoutIfNeeded
UIView*bottomView = [[UIViewalloc]init];
[self.viewaddSubview:bottomView];
[bottomViewmas_makeConstraints:^(MASConstraintMaker *make) {
make.height.mas_equalTo(60);
make.left.right.bottom.mas_equalTo(self.view);
}];
[self.view layoutIfNeeded];
//设置阴影
[bottomViewLX_SetShadowPathWith:[UIColor blackColor] shadowOpacity:0.1 shadowRadius:1 shadowSide:LXShadowPathTop shadowPathWidth:1];