Adding CALayer to UIView with the ability to redraw when changing orientation

I have a subclass of UIView that is assigned by backgroundViewUITableVieCell. In my subclass of UIView, I add 2 CALayers in the method initWithFrame:.

When the orientation changes, the cell height changes, and I need to reconfigure the positions of my CALayers; basically redraw.

Since CALayers are added to the method initWithFrame:, I cannot redraw them by calling setNeedsDisplay.

I am new to working with CALayers and don’t know how to do it right. How can I add my CALayers so that they redraw the orientation change / or any event that could change the dimensions as a whole?

+3
source share
2 answers

UIView - (void)layoutSubviews;. . .

CoreAnimation, , layoutSublayers.

, .

+3

, KVO .

[self.layer addObserver:self forKeyPath:@"bounds" options:0 context:nil];

, , -observeValueForKeyPath:ofObject:change:context:.

removeObserver:self, .

+4

All Articles