Search code examples
iosanimationcalayercakeyframeanimation

curve Animation direction of rotation?


In my application I use the following animation to make my UIElement follow a circle path in clockwise direction

CGMutablePathRef path = CGPathCreateMutable(); 
CGPathAddArc(path, NULL,viewFormsUI.center.x,viewFormsUI.center.y, 
                     88,radianOf(243),radianOf(0), YES); //viewFormsUI is an UIView 
CAKeyframeAnimation *animation = [CAKeyframeAnimation animationWithKeyPath:@"position"]; 
[animation setPath:path]; 
[animation setDuration:1];
animation.removedOnCompletion = YES;
animation.fillMode = kCAFillModeForwards; 
[animation setAutoreverses:NO];
CFRelease(path); 
[btnRefreshUI.layer addAnimation:animation forKey:@"curveAnimation"];
                             //btnRefreshUI is an UIButton

radianOf is a function which convert angle to radians (just return the value of M_PI*(angle/180))

But the problem is that the UIElement is rotating in anti clockwise direction. I can't find the error in my code, help me out peers.


Solution

  • CGPathAddArc(path, NULL, viewFormsUI.center.x, viewFormsUI.center.y, 88, radianOf(243), radianOf(0), YES);

    try just change YES to NO

    CGPathAddArc(path, NULL, viewFormsUI.center.x, viewFormsUI.center.y, 88, radianOf(243), radianOf(0), NO);

    this is - bool clockwise