关键帧动画
发布日期:2022-02-15 02:36:16
浏览次数:5
分类:技术文章
本文共 2032 字,大约阅读时间需要 6 分钟。
#import "CZViewController.h" @interface CZViewController () @property ( nonatomic , strong ) UIView *myView; @end @implementation CZViewController - ( UIView *)myView { if ( _myView == nil ) { _myView = [[ UIView alloc ] initWithFrame : CGRectMake ( 110 , 100 , 100 , 100 )]; _myView . backgroundColor = [ UIColor redColor ]; [ self . view addSubview : _myView ]; } return _myView ; } - ( void )viewDidLoad { [ super viewDidLoad ]; [ self myView ]; } // 点击屏幕时调用 - ( void )touchesBegan:( NSSet *)touches withEvent:( UIEvent *)event { [ self positionAnim1 ]; } #pragma mark - 关键帧动画 /** 摇晃动画 */ - ( void )shake { if ([ self . myView . layer animationForKey : @"shake" ]) return ; CAKeyframeAnimation *anim = [ CAKeyframeAnimation animationWithKeyPath : @"transform.rotation" ]; anim. values = @[@( - M_PI / 36) , @( M_PI / 36) , @( - M_PI / 36)] ; // anim.duration = 0.5f; anim. repeatCount = MAXFLOAT ; [ self . myView . layer addAnimation :anim forKey : @"shake" ]; } // 图层在指定的路径上运动 - ( void )positionAnim1 { CAKeyframeAnimation *anim = [ CAKeyframeAnimation animationWithKeyPath : @"position" ]; // 绘制圆形路径 anim. path = [ UIBezierPath bezierPathWithOvalInRect : CGRectMake ( 60 , 100 , 200 , 200 )]. CGPath ; // 持续时间 anim. duration = 2.0f ; [ self . myView . layer addAnimation :anim forKey : nil ]; } // 在指定的几个点上运动 - ( void )positionAnim { CAKeyframeAnimation *anim = [ CAKeyframeAnimation animationWithKeyPath : @"position" ]; NSValue *p1 = [ NSValue valueWithCGPoint : CGPointMake ( 50 , 50 )]; NSValue *p2 = [ NSValue valueWithCGPoint : CGPointMake ( 50 , 300 )]; NSValue *p3 = [ NSValue valueWithCGPoint : CGPointMake ( 250 , 300 )]; NSValue *p4 = [ NSValue valueWithCGPoint : CGPointMake ( 250 , 50 )]; NSValue *p5 = [ NSValue valueWithCGPoint : CGPointMake ( 50 , 50 )]; anim. values = @[ p1, p2, p3, p4, p5 ] ; // 图层会保持显示动画执行后的状态 // 设置保存动画的最新状态 anim. fillMode = kCAFillModeForwards ; // 设置动画执行完毕之后不删除动画 anim. removedOnCompletion = NO ; anim. duration = 2.0f ; [ self . myView . layer addAnimation :anim forKey : nil ]; } @end转载地址:https://blog.csdn.net/Peter_AM/article/details/49983345 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!
发表评论
最新留言
网站不错 人气很旺了 加油
[***.192.178.218]2024年03月28日 12时27分24秒
关于作者
喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
推荐文章
Unity中物体移动方法详解
2019-04-27
使用对象池优化性能
2019-04-27
Unity中的UI方案(基础版)
2019-04-27
Lua(一)——Lua介绍
2019-04-27
Lua(二)——环境安装
2019-04-27
Unity中父子物体的坑
2019-04-27
基础知识——进位制
2019-04-27
Lua(十二)——表
2019-04-27
Lua(十三)——模块与包
2019-04-27
Lua(四)——变量
2019-04-27
Lua(十四)——元表
2019-04-27
Lua(十五)——协同程序
2019-04-27
Lua(十六)——文件
2019-04-27
Lua(十七)——面向对象
2019-04-27
Lua(十八)——错误处理,垃圾回收
2019-04-27
xLua(一)——介绍
2019-04-27
xLua(二)——下载
2019-04-27
xLua(三)——在C#中访问Lua代码
2019-04-27
xLua(四)——C#访问Lua的基本类型
2019-04-27
xLua(五)——C#访问Lua的table
2019-04-27