In my application, I have a UIView that uses CALayer to achieve the shadow:
@implementation MyUIView - (instancetype) initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if(!self) return self; self.layer.shadowColor = [UIColor colorWithWhite:0 alpha:.2].CGColor; self.layer.shadowOffset = CGSizeMake(0, 2); self.layer.shadowOpacity = 1; self.layer.shadowRadius = 1; return self; } @end
If I need anything closer to reasonable performance, I have to define a CALayer shadowPath :
@implementation MyUIView - (void) setFrame:(CGRect)frame { [super setFrame:frame]; self.layer.shadowPath = CGPathCreateWithRect(self.bounds, NULL); } @end
I noticed two things when I revive this UIView :
If I don't , use shadowPath , the shadow animates well with rotations and frame resizing. The danger here is very slow animation and a general lack of performance.
If I do , use shadowPath whenever the UIView animation is smooth and timely, however the shadow transition itself is much more blocky (and less smooth) than without shadowPath .
<strong> Examples:
Edit:
It is worth noting that these animations are implicit - I myself do not call them. They are the result of rotation of the UIViewController with the device orientation. The shadow is on a UIView that changes size during rotation.
source share