So I am doing some custom animations on my navigationcontroller and the way it pushes and pops the viewControllers.
Everything runs smooth. As soon as I add the following code (In a subclass of UINavigationController
), I face a huge performance hit. After adding a shadow all animations become very laggy. Is this expected or am I doing something wrong in the code?
// This code gets called once during NavigationController initialization. [self.view setClipsToBounds:NO]; [self.view.layer setCornerRadius:5]; [self.view.layer setShadowOffset:CGSizeMake(0, 20)]; [self.view.layer setShadowColor:[[UIColor yellowColor] CGColor]]; [self.view.layer setShadowRadius:20.0]; [self.view.layer setShadowOpacity:1];
EDIT:
Changed my shadow radius to 1 and it's still slow
shadowOpacity : the opacity of the layer's shadow. The value of this property must be in the range 0.0 (invisible) to 1.0 (opaque). The default value of this property is 0.0 .
ShadowOffset does what its name suggests, it offsets the shadow based on the input. For example, if you have a shadow radius of 10 and have an offset of (5, 5), the shadow will have a width of 5 on top/left and 15 on bottom/right.
shadowOffset controls how far the shadow is moved away from its view. This defaults to 3 points up from the view. shadowOpacity controls how transparent the shadow is. This defaults to 0, meaning “invisible”. shadowPath controls the shape of the shadow.
The blur radius (in points) used to render the layer's shadow.
self.view.layer.shouldRasterize = YES; self.view.layer.rasterizationScale = UIScreen.mainScreen.scale;
I was recently having some issues with slow CALayer shadows, and that simple line of code fixed up everything for me!
You should expect a slowdown from adding a shadow. A shadowRadius
of 20 is very high and will be especially slow.
The other key to improve shadow rendering speed: set the shadowPath
property. It can help dramatically.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With