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一个圆)之前已经发生,并且计算正确。
- 检测用户是否input了UITextField
- 错误使用未parsing的标识符GMSPlacePickerConfig&GooglePlacePicker? (Google Places 2.0)
- 我可以知道究竟需要什么样的认可才能做到这一点?
- 如何使用Swift更改MKAnnotation Color?
- 用于iBeacon设备的UUID,主要,次要设置
- 使用隐藏的SFSafariViewController获取Safari cookie
- UIDocumentInteractionController – 更改背景颜色并阻止状态栏弹出
- iOS:推送通知作为Web服务轮询的“触发器”?
- 如何在运行时获得iOS设备CPU架构?