-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event 20 { 21 //1.创建核心动画 22 CAKeyframeAnimation *keyAnima=[CAKeyframeAnimation animation]; 23 //平移 24 keyAnima.keyPath=@"position"; 25 //1.1告诉系统要执行什么动画 26 NSValue *value1=[NSValue valueWithCGPoint:CGPointMake(100, 100)]; 27 NSValue *value2=[NSValue valueWithCGPoint:CGPointMake(200, 100)]; 28 NSValue *value3=[NSValue valueWithCGPoint:CGPointMake(200, 200)]; 29 NSValue *value4=[NSValue valueWithCGPoint:CGPointMake(100, 200)]; 30 NSValue *value5=[NSValue valueWithCGPoint:CGPointMake(100, 100)]; 31 keyAnima.values=@[value1,value2,value3,value4,value5]; 32 //1.2设置动画执行完毕后,不删除动画 33 keyAnima.removedOnCompletion=NO; 34 //1.3设置保存动画的最新状态 35 keyAnima.fillMode=kCAFillModeForwards; 36 //1.4设置动画执行的时间 37 keyAnima.duration=4.0; 38 //1.5设置动画的节奏 39 keyAnima.timingFunction=[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]; 40 41 //设置代理,开始—结束 42 keyAnima.delegate=self; 43 //2.添加核心动画 44 [self.customView.layer addAnimation:keyAnima forKey:nil]; 45 } 46 47 -(void)animationDidStart:(CAAnimation *)anim 48 { 49 NSLog(@"开始动画"); 50 } 51 52 -(void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag 53 { 54 NSLog(@"结束动画"); 55 }
iOS开发UI篇—核心动画(关键帧动画)
最新推荐文章于 2021-11-15 18:00:33 发布