我想用CAPropertyAnimations的iOS画出流畅的动画 [英] I want to draw a Smooth animations in iOS using CAPropertyAnimations

查看:682
本文介绍了我想用CAPropertyAnimations的iOS画出流畅的动画的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

它的工作原理是这样

我要显示一个圆的动画。它逐渐变大。我不想改变它的位置。

I want to show a circle animation. it become bigger gradually. I don't want to change it's position.

我的code是如下,和圆的位置也移动,如何处理这事。

my code is as following, and the circle's position also moves, how can deal with this.

- (void)viewDidLoad
{
[super viewDidLoad];
int radius = 20;
CGPoint drawPoint = CGPointMake(self.view.frame.size.width/2 -radius,self.view.frame.size.height/2+radius*2);
CAShapeLayer *circle = [CAShapeLayer layer];
// Make a circular shape
circle.path = [UIBezierPath bezierPathWithArcCenter:drawPoint radius:radius startAngle:0 endAngle:M_PI*2 clockwise:NO].CGPath;
// Configure the apperence of the circle
UIColor *pointColor =[UIColor alloc];
pointColor = [UIColor redColor];
circle.fillColor = pointColor.CGColor;
circle.strokeColor = pointColor.CGColor;
circle.lineWidth = 1;
// Add to parent layer
[self.view.layer addSublayer:circle];
// Configure animation
CABasicAnimation *pathAnimation = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
// Set the initial and the final values
[pathAnimation setFromValue:[NSNumber numberWithFloat:0.5f]];
[pathAnimation setToValue:[NSNumber numberWithFloat:1.5f]];
[pathAnimation setDuration:1.0f];
[pathAnimation setRepeatCount:1.0f];
[pathAnimation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
[circle addAnimation:pathAnimation forKey:@"changePathAnimation"];    //--draw circle

}

推荐答案

您动漫(0 0)在屏幕坐标是相对于你的CAShapeLayer,这是注册点。

Your animation is relative to the registration point of your CAShapeLayer, which is (0, 0) in screen coordinates.

试试这个:

circle.path = [UIBezierPath bezierPathWithArcCenter:CGPointZero radius:radius startAngle:0 endAngle:M_PI*2 clockwise:NO].CGPath;
circle.position = drawPoint;

这篇关于我想用CAPropertyAnimations的iOS画出流畅的动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆