0

I am drawing a pie graph and on tap, I am rotating it to the next pie with

CGContextRotateCTM(context, degreesToRadians(mAngle)).

Is there a way to animate this transition? Could you please post an example?

Oleg Danu
  • 4,149
  • 4
  • 29
  • 47

1 Answers1

0

I think if you really want rotate your chart just changing drawing code you'll need to create a timer and change rotation angle in its method and also make view redraw there.

Instead of applying rotation in drawing code I'd rotate the view with chart itself if that's possible - either with UIView animations or with CALayer animations - they are pretty straightforward and provide much more flexibility. e.g.

[UIView animateWithDuration:1.0f 
                 animations:^{
                     view.transform = CGAffineTransformMakeRotation(mAngle);
                 }];

Will rotate your view on mAngle with animation during 1 sec (method is available starting iOS4). Also if you want to rotate your view by 360 degrees or more you'll need to use CALayer animation (check this question for details).

Also using standard animations most likely won't make your view redraw, so it will be more efficient.

Community
  • 1
  • 1
Vladimir
  • 170,431
  • 36
  • 387
  • 313
  • So this is the question how would I animate it using CALayer animations or UIView animations? – Oleg Danu Mar 11 '11 at 07:35
  • Actually I don't want to rate my view, or even my layer. When I use CGContextRotateCTM(context, degreesToRadians(mAngle)) it only rotates the user coordinate system, it means that I have a PIE Chart in that layer, and it is only the pie chart rotated, but not the layer, or even the view. – Oleg Danu Mar 11 '11 at 12:41
  • but why not put your chart to a separate view? if you can't do that - create a timer that fires frequently enough (say, 60 times/sec) and force your view to redraw in it (adjusting mAngle) – Vladimir Mar 11 '11 at 12:49
  • hmmm, this is what I wanted to ommit. I just want to use UIView animations or Core animation or CALAyer animation, if possible. – Oleg Danu Mar 11 '11 at 12:58
  • then move your chart to a separate view or layer and apply my approach – Vladimir Mar 11 '11 at 13:00
  • I can't apply like so, because it is not smooth enough when I am rotating it with touchesMoved. – Oleg Danu Mar 11 '11 at 13:08