Autolayout(与砌体)与angular落半径

我想用砌体布局一个圆形的UIImageView。 所以我创build了这样的UIImageView:

[self.imageView mas_makeConstraints:^(MASConstraintMaker *make) { make.centerX.equalTo(self.mas_centerX); make.top.equalTo(self.mas_top).with.offset([[UIView ub_padding] floatValue]); make.bottom.equalTo(self.descriptionLabel.mas_top).with.offset(-[[UIView ub_padding] floatValue]); make.height.equalTo(self.descriptionLabel.mas_height).priorityHigh(); make.width.equalTo(self.imageView.mas_height); }]; 

然后我创build了ImageView的约束

 [self.imageView mas_makeConstraints:^(MASConstraintMaker *make) { make.centerX.equalTo(self.mas_centerX); make.top.equalTo(self.mas_top).with.offset([[UIView ub_padding] floatValue]); make.bottom.equalTo(self.descriptionLabel.mas_top).with.offset(-[[UIView ub_padding] floatValue]); make.height.equalTo(self.descriptionLabel.mas_height).priorityHigh(); make.width.equalTo(self.imageView.mas_height); }]; 

然后我尝试应用这些约束,然后设置拐angular半径。

  [self setNeedsUpdateConstraints]; [self updateConstraintsIfNeeded]; [self layoutIfNeeded]; self.imageView.layer.cornerRadius = self.imageView.frame.size.width/2; 

但是self.imageView的框架仍然没有设置(但是当我在模拟器上查看它的时候,它会被放弃)。 布局完成后调用什么方法?

在视图的layoutSubviews方法中调用super...之后设置angular点半径:

 -(void)layoutSubviews{ [super layoutSubviews]; [self applyCornerRadii]; } 

这样可以确保布局在尝试应用angular半径(在我的情况下是50%的高度/宽度创build一个圆)之前已经发生,并且计算正确。