- 遇到的坑留個筆記
-
項(xiàng)目中用Masonry布局,有地方需要用到frame,不管怎么取值都是0,坑死我啦
- (void)initTopView{
_cancelButton = ({
UIButton *button = [UIButton buttonWithTitle:@"取消" titleColor:[UIColor blackColor] fontSize:14 target:self action:@selector(cancelButtonClick:)];
[self.view addSubview:button];
[button mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerY.equalTo(_searchBar);
make.right.equalTo(self.view.mas_right).offset(-5);
}];
button;
});
_cancelButton.hidden = YES;
_topView = ({
UIView *view = [[UIView alloc] init];
view.backgroundColor = [UIColor whiteColor];
[self.view addSubview:view];
[view mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(_searchBar.mas_bottom).offset(5);
make.left.right.equalTo(self.view);
make.height.equalTo(self.view).multipliedBy(0.2);
}];
view;
});
_consultButton = ({
UIButton *button = [UIButton buttonWithTopAndBottomTitle:@"咨詢記錄" titleColor:[UIColor blackColor] fontSize:14 imageName:@"publish-text" selectedImageName:@"publish-text" target:self action:@selector(consultButtonClick:)];
[self.topView addSubview:button];
[button mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerY.equalTo(_topView).offset(-13);
make.centerX.equalTo(_topView);
}];
button;
});
_doctorButton = ({
UIButton *button = [UIButton buttonWithTopAndBottomTitle:@"問醫(yī)生" titleColor:[UIColor blackColor] fontSize:13 imageName:@"publish-audio" selectedImageName:@"publish-text" target:self action:@selector(doctortButtonClick:)];
[self.view addSubview:button];
[button mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(_consultButton.mas_top);
make.centerX.equalTo(_topView).multipliedBy(0.3);
}];
button;
});
_ideaButton = ({
UIButton *button = [UIButton buttonWithTopAndBottomTitle:@"意見反饋" titleColor:[UIColor blackColor] fontSize:13 imageName:@"publish-picture" selectedImageName:@"publish-text" target:self action:@selector(doctortButtonClick:)];
[self.view addSubview:button];
[button mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(_consultButton.mas_top);
make.centerX.equalTo(_topView).multipliedBy(1.7);
}];
button;
});
}
-
不加這下面兩句因谎,獲得的尺寸會是你使用Masonry布局 或(xib)里的未完成autolayout適配時的尺寸
- storyboard同理(把這兩句寫在viewDidLoad:方法中亏推,將contentView換成控制器的view)
[self.contentView setNeedsLayout];
[self.contentView layoutIfNeeded];
- 這里可以提前獲得autolayout完成后適配后的子控件的真實(shí)frame
self.imageView.layer.cornerRadius = self.imageView.frame.size.width / 2;
self.imageView.clipsToBounds = YES;
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者