1. 先看下面這段代碼:
[self.scrollView mas_makeConstraints:^(MASConstraintMaker *make) {? ? make.edges.mas_equalTo(UIEdgeInsetsMake(0,0,0,0));}];NSLog(@"%@",self.scrollView);
打印結(jié)果:
<UIScrollView: 0x7fc461014000; frame = (0 0; 0 0);
2. 再看一段代碼:
[self.scrollView mas_makeConstraints:^(MASConstraintMaker *make) {? ? make.edges.mas_equalTo(UIEdgeInsetsMake(0,0,0,0));}];// 先調(diào)用superView的layoutIfNeeded方法再獲取frame[self.view layoutIfNeeded];NSLog(@"%@",self.scrollView);
?打印結(jié)果:
<UIScrollView: 0x7fc72d016000; frame = (0 0; 375 667);
所以我們可以通過調(diào)用layoutIfNeeded再去獲取 frame
實(shí)際開發(fā)中遇到的問題
1.用Masonry布局一個(gè) uilabel,然后用貝塞爾曲線繪制圓角途蒋,如果用貝塞爾曲線繪制圓角的方法寫在awakeFromNib童芹,layoutSubviews都是有問題的兄一。因?yàn)樵谶@些函數(shù)方法拿到的frame 都不是正確的伴鳖,所以有問題筷屡。所以我們可以先給控件賦值后,再調(diào)layoutIfNeeded莽鸭,再用貝塞爾曲線繪制圓角
? ? self.typeTipLabel.text = @"";
? ? [self layoutIfNeeded];
? ? [self.typeTipLabel setCornerWithCornerRadii:CGSizeMake(5, 5) byRoundingCorners:UIRectCornerBottomLeft];
2.用Masonry布局一個(gè)?uiview 金蜀,然后設(shè)置陰影也沒有效果刷后。也要先調(diào)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];
? //設(shè)置陰影
? [bottomViewLX_SetShadowPathWith:[UIColor blackColor] shadowOpacity:0.1 shadowRadius:1 shadowSide:LXShadowPathTop shadowPathWidth:1];