Mixed usage of Auto Layout with non-Auto Layout

suggest change

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 the view’s frame. maskLayer here is the view’s own property.

// CustomView.m
- (void)layoutSubviews {
    [super layoutSubviews];
    // Auto Layout has updated the frame. Use it for the mask.
    CALayer *maskLayer = self.maskLayer;
    maskLayer.bounds = self.bounds;
}

Further mask changes belong after that assignment. In a view controller, viewDidLayoutSubviews is the matching place:

- (void)viewDidLayoutSubviews {
    [super viewDidLayoutSubviews];
    // Subviews have been positioned. A frame assigned here is replaced on the next pass if constraints still position that view.
    self.customView.frame = self.containerView.frame;
}

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents