coreAnimation核心动画(二)CAKeyframeAnimation
2015-11-21 23:23
351 查看
// // ViewController.m // coreAnimation // // Created by ys on 15/11/21. // Copyright (c) 2015年 ys. All rights reserved. // #import "ViewController.h" @interface ViewController () @property (weak, nonatomic) IBOutlet UIView *blackView; @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; } - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { CAKeyframeAnimation *anim = [CAKeyframeAnimation animation]; anim.keyPath = @"position"; anim.removedOnCompletion = NO; anim.fillMode = kCAFillModeForwards; anim.duration = 2.0; CGMutablePathRef path = CGPathCreateMutable(); CGPathAddEllipseInRect(path, NULL, CGRectMake(100, 100, 200, 200)); anim.path = path; CGPathRelease(path); // 设置动画的执行节奏 // kCAMediaTimingFunctionEaseInEaseOut : 一开始比较慢, 中间会加速, 临近结束的时候, 会变慢 anim.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]; anim.delegate = self; [self.blackView.layer addAnimation:anim forKey:nil]; } #pragma mark - 动画的代理方法 #pragma mark 动画开始的时候调用 - (void)animationDidStart:(CAAnimation *)anim { NSLog(@"animationDidStart"); } #pragma mark 动画结束的时候调用 - (void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag { NSLog(@"animationDidStop"); } - (void)testMove { // CABasicAnimation fromValue --> toValue CAKeyframeAnimation *anim = [CAKeyframeAnimation animation]; anim.keyPath = @"position"; NSValue *v1 = [NSValue valueWithCGPoint:CGPointZero]; NSValue *v2 = [NSValue valueWithCGPoint:CGPointMake(100, 0)]; NSValue *v3 = [NSValue valueWithCGPoint:CGPointMake(100, 200)]; NSValue *v4 = [NSValue valueWithCGPoint:CGPointMake(0, 200)]; anim.values = @[v1, v2, v3, v4]; // anim.keyTimes = @[@(0.5), @(0.25), @(0.25)]; anim.duration = 2.0; anim.removedOnCompletion = NO; anim.fillMode = kCAFillModeForwards; [self.blackView.layer addAnimation:anim forKey:nil]; } @end
相关文章推荐
- 最短路径 Dijkstra(迪杰斯特拉)
- 设计模式之反射与配置文件
- 这个功能很简单,要做多久
- Kappa系数
- C++ 可变参函数实现
- Office 365 Service Communications API operations--Get Historical Status
- java基础部分
- ubuntu常用软件包deb的安装与卸载
- 南大软院大神养成计划--第四天JavaScript
- pat 1072 Gas Station
- iOS NSDate
- tmp_table_size
- ubuntu网页无法看视频
- Epoll详解及源码分析
- HDU 5569 (BC#63)DP
- OpenCV中特征点提取和匹配的通用方法
- Matlab读取txt文本并且绘制曲线
- 标签
- Office 365 Service Communications API operations--Get Current Status
- Java8中的默认方法和Lambda的使用