CAKeyframeAnimation-核心动画-帧动画

来源:互联网 发布:中国武器知乎 编辑:程序博客网 时间:2024/05/16 07:20

////  ViewController.m//  002-核心动画-帧动画-CAKeyframeAnimation////  Created by LTOVE on 15/10/15.//  Copyright (c) 2015年 LTOVE. All rights reserved.//#import "ViewController.h"@interface ViewController ()@property (weak, nonatomic) IBOutlet UIImageView *imgView;@end@implementation ViewController- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {//    创建一个帧动画    CAKeyframeAnimation *animation = [CAKeyframeAnimation animation];            animation.keyPath = @"position";//    设置动画的路径    NSValue *value1 = [NSValue valueWithCGPoint:CGPointMake(40, 40)];    NSValue *value2 = [NSValue valueWithCGPoint:CGPointMake(240, 40)];    NSValue *value3 = [NSValue valueWithCGPoint:CGPointMake(540, 40)];    NSValue *value4 = [NSValue valueWithCGPoint:CGPointMake(40, 250)];    //    把上边的路径包装成数组,第一个是开始状态,第二个是结束的状态    animation.values = @[value1,value2,value3,value4,value1];//    设置动画的时间    animation.duration = 5;#pragma mark ****************设置动画的节奏begin****************    //kCAMediaTimingFunctionEaseIn 先慢后快    //kCAMediaTimingFunctionEaseOut 先快后慢    //kCAMediaTimingFunctionLinear 线性匀速    //kCAMediaTimingFunctionEaseInEaseOut 中间快两边慢    #pragma mark ****************设置动画的节奏end****************    animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn];#warning path 的优先级比valus高//    设置路径    CGMutablePathRef path = CGPathCreateMutable();    CGFloat screenW = [UIScreen mainScreen].bounds.size.width;//    添加一个圆的路径    CGPathAddEllipseInRect(path, nil, CGRectMake(0, 0, screenW, screenW));    animation.path = path;    CFRelease(path);    animation.repeatCount = 4;            //    添加动画    [self.imgView.layer addAnimation:animation forKey:nil];}@end


0 0
原创粉丝点击