CAKeyframeAnimation简单旋转动画
2015-02-01 16:55
447 查看
使用关键帧动画做的一个简单的动画,效果如下:
![](http://img.blog.csdn.net/20150201165855289?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvdTAxNDA4NDA4MQ==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center)
主要代码如下:
使用 CGPathCreateWithEllipseInRect(),创建一个圆形的 CGPath 作为关键帧动画的 path。
使用 calculationMode 是控制关键帧动画时间的另一种方法。我们通过将其设置为 kCAAnimationPaced,让 Core Animation 向被驱动的对象施加一个恒定速度,不管路径的各个线段有多长。将其设置为 kCAAnimationPaced 将无视所有我们已经设置的 keyTimes。
设置 rotationMode 属性为 kCAAnimationRotateAuto 确保飞船沿着路径旋转。
如果将rotationMode设置为nil,效果会如下:
主要代码如下:
_sunView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)]; _sunView.backgroundColor = [UIColor orangeColor]; _sunView.center = self.view.center; _sunView.layer.cornerRadius = 100 /2.0; [self.view addSubview:_sunView]; CGRect boundingRect = CGRectMake(CGRectGetMidX(_sunView.frame)-150, CGRectGetMidY(_sunView.frame)- 300 / 2.0, 300, 300); UIView *blackView = [[UIView alloc] initWithFrame:boundingRect]; blackView.backgroundColor = [UIColor blackColor]; [self.view insertSubview:blackView belowSubview:_sunView]; _earthView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 50, 50)]; _earthView.backgroundColor = [UIColor redColor]; _earthView.center = blackView.frame.origin; [self.view addSubview:_earthView]; CAKeyframeAnimation *orbit = [CAKeyframeAnimation animation]; orbit.keyPath = @"position"; orbit.path = CFAutorelease(CGPathCreateWithEllipseInRect(CGRectMake(0, 0, 300, 300), NULL)); orbit.duration = 4; orbit.additive = YES; orbit.repeatCount = HUGE_VALF; orbit.calculationMode = kCAAnimationPaced; orbit.rotationMode = kCAAnimationRotateAuto; [_earthView.layer addAnimation:orbit forKey:@"orbit"];
使用 CGPathCreateWithEllipseInRect(),创建一个圆形的 CGPath 作为关键帧动画的 path。
使用 calculationMode 是控制关键帧动画时间的另一种方法。我们通过将其设置为 kCAAnimationPaced,让 Core Animation 向被驱动的对象施加一个恒定速度,不管路径的各个线段有多长。将其设置为 kCAAnimationPaced 将无视所有我们已经设置的 keyTimes。
设置 rotationMode 属性为 kCAAnimationRotateAuto 确保飞船沿着路径旋转。
如果将rotationMode设置为nil,效果会如下:
相关文章推荐
- CAKeyframeAnimation 旋转动画
- IOS Animation-CAKeyframeAnimation例子(简单动画实现)
- CABaseAnimation + CAAnimationGroup + CAKeyframeAnimation的简单动画
- CAKeyframeAnimation简单实用
- Animation -- 实现简单的2D动画:从小到大,旋转出场且透明度由0到1
- iOSCoreAnimation动画系列教程(二):CAKeyFrameAnimation【包会】
- CAKeyFrameAnimation 的简单用法
- coreAnimation核心动画(二)CAKeyframeAnimation
- CAKeyframeAnimation path 绘制动画 和 《CALayer 自定义属性绘制动画》 的比较
- 【iOS开发-动画】CAKeyframeAnimation创建动画
- UI 动画之CALayer+CAAnimation 之 CAKeyframeAnimation
- Core Animation(核心动画)CABasicAnimation CAKeyframeAnimation CAAnimationGroup
- CABasicAnimation,CAKeyframeAnimation,CATransition,CAAnimationGroup,UIBezierPath之间做动画的不同点和各自的使用范围。
- html5 requestAnimationFrame制作动画:旋转风车
- CAKeyframeAnimation-核心动画-帧动画
- iOS动画:UIView动画和CALayer动画(CABasicAnimation、CAKeyframeAnimation的使用)
- 【原】iOSCoreAnimation动画系列教程(二):CAKeyFrameAnimation【包会】
- Animation简单的3D动画旋转
- 猫猫学IOS(四十)UI之核心动画_抖动效果_CAKeyframeAnimation
- CAKeyframeAnimation的简单使用