-(void)setFrame:(CGRect)frame { [super setFrame:frame]; [self.layout setCornerRadius:frame.size.width/10.0]; }
这对于图像的初始显示非常有用,但是如果图像的大小由于设备旋转或某些其他机制而发生变化,则不会调用此方法来实现调整大小.
我正在使用autolayout,我想知道当我的约束调整视图大小时调用UIView(以及UIImageView)的方法,以便每当调整大小时我都可以重新计算我的角半径.我的(显然是假的)假设是autolayout系统调用setFrame:根据需要移动/调整视图大小.
@H_403_8@解决方法
Custom views that set up constraints themselves should do so by overriding this method
….
Before layout is performed,your implementation of updateConstraints will be invoked,allowing you to verify that all necessary constraints for your content are in place at a time when your custom view’s properties are not changing.
或者从layoutSubviews上的文档:
You should override this method only if the autoresizing and constraint-based behaviors of the subviews do not offer the behavior you want. You can use your implementation to set the frame rectangles of your subviews directly.
但如果您需要在轮换时进行此操作,请查看
willTransitionToTraitCollection:withTransitionCoordinator:
@H_403_8@ @H_403_8@Implementors of this method can use it to adapt the interface based on the values in the newCollection parameter. A common use of this method is to make changes to the high-level presentation style when the current size class changes.