Search code examples
ioscore-animationuiinterfaceorientation

iOS Screen Rotation Degraded When Shadows Are Visible


This isn't in reference to any particular code, but I've noticed that when I have a UIView that has a shadow added to it's layer, the animation when rotating between interface orientations becomes much more laggy/choppy.

Has anyone noticed this issue or found a workaround?


Solution

  • There are things which are very expensive in terms of CPU time. Check it out in Instruments some time.

    • shadows
    • bezier paths
    • bezier paths with dashes (really expensive)

    Thats not a comprehensive list. I suspect gradients will be there too.

    If you find these things are degrading your animation or redraw you will need to toggle them in the UIViewController methods.

    -(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
    {
    //disable shadows + expensive drawing
    }
    
    - (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
    {
    //enable shadows + expensive drawing
    }