如何在圆形路径中为uibutton设置动画(Objective C)

时间:2013-10-23 10:15:58

标签: iphone uibutton core-animation

float degrees = -30.0;
float radians = (degrees/180.0) * M_PI;

[UIView animateWithDuration:0.5 animations:^
 {
     bottomRoundedView.transform = CGAffineTransformMakeRotation(radians);
 }
 ];

1 个答案:

答案 0 :(得分:0)

尝试以下代码,

CAKeyframeAnimation *pathAnimation = [CAKeyframeAnimation animationWithKeyPath:@"position"];
pathAnimation.calculationMode = kCAAnimationPaced;
pathAnimation.fillMode = kCAFillModeForwards;
pathAnimation.removedOnCompletion = NO;
pathAnimation.repeatCount = INFINITY;
pathAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear];
pathAnimation.duration = 3.0;

CGMutablePathRef curvedPath = CGPathCreateMutable();
CGRect circleContainer = CGRectMake(0, 0, 100, 100); 
CGPathAddEllipseInRect(curvedPath, NULL, circleContainer);

pathAnimation.path = curvedPath;
CGPathRelease(curvedPath);

[self.yourbutton.layer addAnimation:pathAnimation forKey:@"myCircleAnimation"];

circleContainer是您需要显示圆形动画的框架。 pathAnimation.duration用于调整动画的速度。

如果要停止动画,请调用

[self.yourbutton.layer removeAnimationForKey:@"myCircleAnimation"];