核心动画-06-关键帧动画-day4
1 // 2 // ViewController.m 3 // 06 关键帧动画 4 // 5 // Created by ZhuJiaCong on 16/4/18. 6 // Copyright © 2016年 wxhl. All rights reserved. 7 // 8 9 #import "ViewController.h" 10 11 @interface ViewController () 12 { 13 CGMutablePathRef _path; 14 } 15 @property (weak, nonatomic) IBOutlet UIView *redView; 16 17 @end 18 19 @implementation ViewController 20 21 - (void)viewDidLoad { 22 [super viewDidLoad]; 23 24 _redView.layer.cornerRadius = 10; 25 26 27 28 } 29 30 31 - (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event { 32 33 //关键帧动画 34 // CAKeyframeAnimation *keyFrame = [CAKeyframeAnimation animationWithKeyPath:@"position"]; 35 // 36 // //创建帧 37 // CGPoint point1 = CGPointMake(100, 100); 38 // CGPoint point2 = CGPointMake(150, 100); 39 // CGPoint point3 = CGPointMake(100, 150); 40 // CGPoint point4 = CGPointMake(150, 150); 41 // CGPoint point5 = CGPointMake(200, 100); 42 // CGPoint point6 = CGPointMake(100, 200); 43 // 44 // 45 // NSArray *array = @[[NSValue valueWithCGPoint:point1], 46 // [NSValue valueWithCGPoint:point2], 47 // [NSValue valueWithCGPoint:point3], 48 // [NSValue valueWithCGPoint:point4], 49 // [NSValue valueWithCGPoint:point5], 50 // [NSValue valueWithCGPoint:point6] 51 // ]; 52 // 53 // keyFrame.values = array; 54 // 55 // keyFrame.duration = 3; 56 // 57 // //将动画添加到图层上去 58 // [_redView.layer addAnimation:keyFrame forKey:@"keyFrame"]; 59 60 61 62 63 if (_path) { 64 CGPathRelease(_path); 65 _path = NULL; 66 } 67 68 //创建路径 69 _path = CGPathCreateMutable(); 70 //设置路径起点 71 UITouch *touch = [touches anyObject]; 72 CGPoint location = [touch locationInView:self.view]; 73 CGPathMoveToPoint(_path, NULL, location.x, location.y); 74 75 } 76 77 - (void)touchesMoved:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event { 78 //获取触摸点 添加路径点 79 UITouch *touch = [touches anyObject]; 80 CGPoint location = [touch locationInView:self.view]; 81 82 CGPathAddLineToPoint(_path, NULL, location.x, location.y); 83 84 } 85 86 - (void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event { 87 88 //执行动画 89 CAKeyframeAnimation *keyFrame = [CAKeyframeAnimation animationWithKeyPath:@"position"]; 90 keyFrame.path = _path; 91 92 93 keyFrame.duration = 5; 94 95 96 97 //速度控制函数 98 keyFrame.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]; 99 100 101 [_redView.layer addAnimation:keyFrame forKey:nil]; 102 103 } 104 105 106 107 - (void)didReceiveMemoryWarning { 108 [super didReceiveMemoryWarning]; 109 // Dispose of any resources that can be recreated. 110 } 111 112 @end
时光见证了成长,还很无知,我想一点点幼稚转为有知!
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 智能桌面机器人:用.NET IoT库控制舵机并多方法播放表情
· Linux glibc自带哈希表的用例及性能测试
· 深入理解 Mybatis 分库分表执行原理
· 如何打造一个高并发系统?
· .NET Core GC压缩(compact_phase)底层原理浅谈
· 手把手教你在本地部署DeepSeek R1,搭建web-ui ,建议收藏!
· 新年开篇:在本地部署DeepSeek大模型实现联网增强的AI应用
· Janus Pro:DeepSeek 开源革新,多模态 AI 的未来
· 互联网不景气了那就玩玩嵌入式吧,用纯.NET开发并制作一个智能桌面机器人(三):用.NET IoT库
· 【非技术】说说2024年我都干了些啥