I have a UIView
which has about 8 different CALayer
sublayers added to its layer.
If I modify the view's bounds (animated), then the view itself shrinks (I checked it with a backgroundColor
), but the sublayers' size remains unchanged.
How to solve this?
I used this in the UIView.
Works for me.
2017
The literal answer to this question:
"CALayers didn't get resized on its UIView's bounds change. Why?"
is that for better or worse
needsDisplayOnBoundsChange
defaults to false in
CALayer
.solution,
Indeed, I direct you to this QA
https://stackoverflow.com/a/47760444/294884
which explains, what the hell the critical
contentsScale
setting does; you usually need to equally set that when you set needsDisplayOnBoundsChange.Swift 3 Version
In Custom cell, Add Following lines
Declare first
Then add following lines
I used the same approach that Solin used, but there's a typo in that code. The method should be:
For my purposes, I always wanted the sublayer to be the full size of the parent view. Put that method in your view class.
In your custom view, you need declare variable for your custom layer, don't declare variable in scope init. And just init it once time, don't try set null value and reinit
As [Ole] wrote CALayer does not support autoresizing on iOS. So you should adjust layout manually. My option was to adjust layer's frame within (iOS 7 and earlier)
or (as of iOS 8)