iOS 动画大全(附带gif图片效果), 在实际的开发当中为了达到界面美化的效果,我们经常需要在项目中使用各种动画,在增强界面的动感。总结了个人的开发经验,下面介绍最常用的动画打全(根据图片效果自行选用吧):


  • UIImage类似美团袋鼠奔跑的动画


-(UIImageView *)imageView{if (!_imageView) {_imageView = [[UIImageView alloc]initWithFrame:CGRectMake(30, 30, 100, 100)];_imageView.center = self.view.center;}return _imageView;
}- (void)viewDidLoad {[super viewDidLoad];[self.view addSubview:self.imageView];//会自动查找loading_1,loading_2直到找不到图片为止UIImage *image = [UIImage animatedImageNamed:@"loading_" duration:1];self.imageView.image = image;
}

  • NSTimer定时器动画
-(UIImageView *)imageView{if (!_imageView) {_imageView = [[UIImageView alloc]initWithFrame:CGRectMake(0,100,50,50)];UIImage *image = [UIImage animatedImageNamed:@"loading_" duration:0.5];_imageView.image = image;}return _imageView;
}- (void)viewDidLoad {[super viewDidLoad];[self.view addSubview:self.imageView];[NSTimer scheduledTimerWithTimeInterval:0.02 target:self selector:@selector(changeLocationTimer:) userInfo:nil repeats:YES];// 方式一[self changeLocation];// 方式二
}
-(void)changeLocationTimer:(id)timer{CGRect frame = self.imageView.frame;frame.origin.x += 1;if (frame.origin.x >= self.view.bounds.size.width) {frame.origin.x = -frame.size.width;}self.imageView.frame = frame;
}
-(void)changeLocation{//当动画结束后 自动进入completion块[UIView animateWithDuration:3 animations:^{CGRect frame = self.imageView.frame;frame.origin.x = self.view.frame.size.width;self.imageView.frame = frame;}completion:^(BOOL finished) {CGRect frame = self.imageView.frame;frame.origin.x = -frame.size.width;self.imageView.frame = frame;[self changeLocation];}];
}

  • UIGestureRecognizer动画
- (void)viewDidLoad {[super viewDidLoad];//添加点击手势self.view上,点击某个位置就让图片移动到对应位置UITapGestureRecognizer *tapGR = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tap:)];[self.view addGestureRecognizer:tapGR];
}
-(void)tap:(UITapGestureRecognizer *)gr{CGPoint location = [gr locationInView:self.view];//对于Block参数 一定要切换焦点到提示位置  回车自动生成[UIView animateWithDuration:1 animations:^{_imageView.center = location;}];
}

 - (void)viewDidLoad {[super viewDidLoad];//为商品图片添加点击手势//tips:图片默认是不接受用户操作的_imageView.userInteractionEnabled = YES;UITapGestureRecognizer *tapGR = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tap:)];[self.imageView addGestureRecognizer:tapGR];
}
-(void)tap:(UITapGestureRecognizer *)gr{//商品落入购物车中 但是原来的图片不消失UIImageView *imageView = [[UIImageView alloc]initWithFrame:_imageView.frame];imageView.image = [UIImage imageNamed:@"snow"];[self.view addSubview:imageView];[UIView animateWithDuration:1 animations:^{imageView.center = _label.center;} completion:^(BOOL finished) {//落入购物车之后 把商品图片清除掉//removeFromSuperview 这个方法 是把视图从他的父视图中移除[imageView removeFromSuperview];}];
}

  • UIBezierPath关键帧动画
    //1.让飞机圆形运动UIBezierPath *path = [UIBezierPath bezierPath];[path addArcWithCenter:CGPointMake(160, 240) radius:100 startAngle:3*M_PI_2 endAngle:3*M_PI_2 + 2*M_PI clockwise:YES];//2.创建关键帧动画//keyPath一共三个 position transform opacity//分别代表位置,变形,透明度CAKeyframeAnimation *moveAnimation = [CAKeyframeAnimation animationWithKeyPath:@"position"];//设置关键帧的动画路径为圆形的moveAnimation.path = path.CGPath;//设置动画时长moveAnimation.duration = 3;//定义动画执行完毕后 是否自动删除 默认是yesmoveAnimation.removedOnCompletion = YES;[self.imageView.layer addAnimation:moveAnimation forKey:nil];

  • CABasicAnimation动画

    //缩放动画CABasicAnimation *scaleAnimation = [CABasicAnimation animationWithKeyPath:@"transform"];scaleAnimation.fromValue = [NSValue valueWithCATransform3D:CATransform3DIdentity];scaleAnimation.toValue = [NSValue valueWithCATransform3D:CATransform3DMakeScale(0.1, 0.1, 1)];scaleAnimation.duration = 1;scaleAnimation.autoreverses = YES;//自动反向scaleAnimation.repeatCount = MAXFLOAT;//重复的次数[self.imageView.layer addAnimation:scaleAnimation forKey:nil];

    //透明度动画CABasicAnimation *alphaAnimation =      [CABasicAnimation animationWithKeyPath:@"opacity"];alphaAnimation.fromValue = @1.0;alphaAnimation.toValue = @0;alphaAnimation.duration = 2;alphaAnimation.autoreverses = YES;alphaAnimation.repeatCount = MAXFLOAT;[self.imageView.layer addAnimation:alphaAnimation forKey:nil];

    //创建动画组 批量管理或添加动画CAAnimationGroup *group = [CAAnimationGroup animation];group.animations = @[moveAnimation,scaleAnimation,alphaAnimation];group.duration = 3;//希望动画结束后 图片删除掉 需要通过协议监听group.delegate = self;[self.imageView.layer addAnimation:group forKey:nil];//下方协议方法会在动画结束时自动触发
-(void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag{[self.imageView removeFromSuperview];
}

  • CABasicAnimation动画
CABasicAnimation *animX = [CABasicAnimation animationWithKeyPath:@"transform"];animX.fromValue = [NSValue valueWithCATransform3D:CATransform3DIdentity];//图片绕X轴旋转pi角度animX.toValue = [NSValue valueWithCATransform3D:CATransform3DRotate(self.imageView.layer.transform, M_PI, 1, 0, 0)];animX.duration = 3;[self.imageView.layer addAnimation:animX forKey:nil];CABasicAnimation *animY = [CABasicAnimation animationWithKeyPath:@"transform"];animY.fromValue = [NSValue valueWithCATransform3D:CATransform3DIdentity];//图片绕Y轴旋转pi角度animY.toValue = [NSValue valueWithCATransform3D:CATransform3DRotate(self.imageView.layer.transform, M_PI, 0, 1, 0)];animY.duration = 3;[self.imageView.layer addAnimation:animY forKey:nil];CABasicAnimation *animZ = [CABasicAnimation animationWithKeyPath:@"transform"];animZ.fromValue = [NSValue valueWithCATransform3D:CATransform3DIdentity];//图片绕Z轴旋转pi角度animZ.toValue = [NSValue valueWithCATransform3D:CATransform3DRotate(self.imageView.layer.transform, M_PI, 0, 0, 1)];animZ.duration = 3;[self.imageView.layer addAnimation:animZ forKey:nil];CABasicAnimation *animXYZ = [CABasicAnimation animationWithKeyPath:@"transform"];animXYZ.fromValue = [NSValue valueWithCATransform3D:CATransform3DIdentity];//图片绕X,Y,Z轴旋转pi角度animXYZ.toValue = [NSValue valueWithCATransform3D:CATransform3DRotate(self.imageView.layer.transform, M_PI, 1, 1, 1)];animXYZ.duration = 3;[self.imageView.layer addAnimation:animXYZ forKey:nil];

  • UISnapBehavior/UIDynamicAnimator 闪烁动画
@interface ViewController ()
@property(nonatomic,strong)UIDynamicAnimator *animator;
//闪烁行为c
@property(nonatomic,strong)UISnapBehavior *snap;
@end@implementation ViewController
- (UIDynamicAnimator *)animator {if(_animator == nil) {_animator = [[UIDynamicAnimator alloc] initWithReferenceView:self.view];}return _animator;
}
- (void)viewDidLoad {[super viewDidLoad];UITapGestureRecognizer *tapGR = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tap:)];[self.view addGestureRecognizer:tapGR];
}
-(void)tap:(UIGestureRecognizer *)gr{CGPoint point = [gr locationInView:self.view];//先删除之前的闪烁行为[self.animator removeBehavior:self.snap];self.snap = [[UISnapBehavior alloc]initWithItem:self.planeIV snapToPoint:point];[self.animator addBehavior:self.snap];
}

iOS 动画大全(附带gif图片效果)相关推荐

  1. 安卓设置菊花动画_Android仿ios加载loading菊花图效果

    项目中经常会用到加载数据的loading显示图,除了设计根据app自身设计的动画loading,一般用的比较多的是仿照ios 的菊花加载loading 图,当然一些条件下还会涉及到加载成功/ 失败情况 ...

  2. iOS动画效果、绘制图形

    文章转载自:http://www.cnblogs.com/kenshincui/p/3972100.html 概览 在iOS中随处都可以看到绚丽的动画效果,实现这些动画的过程并不复杂,今天将带大家一窥 ...

  3. iOS动画开发之五——炫酷的粒子效果

    iOS动画开发之五--炫酷的粒子效果 在上几篇博客中,我们对UIView层的动画以及iOS的核心动画做了介绍,基本已经可以满足iOS应用项目中所有的动画需求,如果你觉得那些都还不够炫酷,亦或是你灵光一 ...

  4. iOS动画之【添加商品到购物车】:将商品图片icon 移动到购物车iocn的位置

    文章目录 引言 I.demo下载 II .代码实现 2.1 商品的cell 2.2 开(下)单界面 2.3 下单商品的控制器VC 2.4 动画处理工具类 JoinCartAnimationTool s ...

  5. iOS动画系列之九:实现点赞的动画及播放起伏指示器

    iOS动画系列,共十篇.现在写到第九篇啦.感兴趣的可以通过下面的传输门进到其他几篇文章里面. 第一篇:iOS动画系列之一:通过实战学习CALayer和透视的原理.做一个带时分秒指针的时钟动画(上) 第 ...

  6. ios项目icon和default图片命名规则

    一.应用图片 标准iOS控件里的图片资源,苹果已经做了相应的升级,我们需要操心的是应用自己的图片资源.就像当初为了支持iPhone 4而制作的@2x高分辨率版本(译者:以下简称高分)图片一样,我们要为 ...

  7. iOS 动画基础总结篇

    iOS 动画基础总结篇   动画的大体分类(个人总结可能有误) 分类.png UIView 动画 属性动画 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 1 ...

  8. ios 动画设计_动画和讲故事在设计中的力量

    ios 动画设计 As human beings, we've always been fond of storytelling. Just think of campfire stories, Sa ...

  9. CSS3动画大全(附源码)flex布局,grid布局3d旋转,图像模糊,文字发光

    CSS3动画大全(附源码)3d旋转,图像模糊,文字发光! 文章目录 CSS3动画大全(附源码)3d旋转,图像模糊,文字发光! html代码 css grid布局 flex布局 文字发光 & 图 ...

最新文章

  1. R语言常用包分类总结
  2. java static关键字_好程序员Java教程分享static关键字的理解
  3. 反反复复的磁盘丢失故障处理过程
  4. .Net读取xlsx文件Excel2007
  5. python字符串随机排序_python 随机数使用方法,推导以及字符串,双色球小程序实例...
  6. 台式电脑怎么找不到计算机在哪,台式机没有蓝牙怎么办
  7. Python学习笔记:字典(dict)
  8. python虚拟机 基于寄存器_虚拟机随谈(一):解释器,树遍历解释器,基于栈与基于寄存器,大杂烩...
  9. day①:py流程控制
  10. 没有基础的人可以学python吗-没有任何基础的人,该如何学习Python?「附具体步骤」...
  11. 2021-01-21
  12. 经典的10道C语言例题(含参考代码)
  13. R语言中写入Excel的不同sheet表格
  14. 点云数据的类型主要分为_点云数据处理方法概述
  15. 计算机怎么获取权限删除文件,电脑删除文件需要获取trustedinstaller权限怎么回事...
  16. 京东API接口:item_search - 按关键字搜索商品
  17. layui可以动态添加div吗_js 动态添加元素(div、li、img等)及设置属性的方法
  18. C语言入门“hello word”编写
  19. 关于博文的禁止评论和允许评论
  20. Citrix Receiver 安装指南

热门文章

  1. python tkinter button 透明图片_Tkinter-按钮图像透明背景
  2. html 样式中加小手 鼠标如何设置显示小手状
  3. chrome不能自动播放音频的问题
  4. 玩游戏用什么蓝牙耳机比较好?适合玩游戏的无线蓝牙耳机推荐
  5. 使用bootstarp前端组件集成的table 分页组件 ;简单上手使用实现前端分页功能
  6. JS跳转页面的几种方法
  7. conda使用教程简写
  8. android 渐变画笔,android – 沿路径使用渐变
  9. SAP中AUTHORITY-CHECK 的使用
  10. pytorch yolov5的输入图像尺寸为指定尺寸