I am animating a UIView that contains a graph drawn with CGPath elements
myView.frame=CGRectMake(0,0,1024,768);
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1];
myView.frame=CGRectMake(0,0,0,768);
[UIView commitAnimations];
This works fine the first time that I run this block of code, however I am unable to force myView to update when I use it later by using setNeedsDisplay. When I execute the code the animation happens as expected but it always displays the first graph I send it. I’ve confirmed that the correct information is being sent to the view before I update it.
While I was troubleshooting this I set the destination width of myView to 80.
This causes everything to work properly EXCEPT my CGPath drawing seems to be rasterizing (with some graphs the view gets blurry, others the view looks slightly pixellated). There is NO rasterization that happens when the width is set to 0. This leads me to 3 questions:
1) Am I unable to force a view to redraw if it has a zero width (Does it ‘disappear’ when it’s width is 0)?
2) How do I animate this view without rasterizing the content? This only seems to happen when I change the dimensions of the view, not the position or opacity.
3) Why does the content NOT rasterize when I animate to zero width?
Since a zero-width view has no area, it’s not surprising that it doesn’t want to draw itself.
When you change the size of a view, the view uses its
contentModeproperty to decide how to redraw its contents. The default value ofcontentModeisUIViewContentModeScaleToFit, which means that it simply scales its previous contents to fit the new size. Try setting the view’scontentModeproperty toUIViewContentModeRedraw. This tells it to send itselfsetNeedsDisplaywhen it is resized.