Member-only story
Mixed usage of Auto Layout with non-Auto Layout
1 min readOct 3, 2020
Sometimes you may want to perform some additional actions to Auto Layout calculations done by UIKit itself. Example: when you have a UIView that has a maskLayer, you may need to update maskLayer as soon as Auto
Layout changes UIView’s frame
// CustomView.m- (void)layoutSubviews {
[super layoutSubviews];
// now you can assume Auto Layout did its job
// you can use view's frame in your calculations
CALayer maskLayer = self.maskLayer;
maskLayer.bounds = self.bounds;
...
}
or if you want to take some additional action to Auto Layout in ViewController
- (void)viewDidLayoutSubviews {
[super viewDidLayoutSubviews];
// now you can assume all your subviews are positioned/resized correctly
self.customView.frame = self.containerView.frame;}