UIView动画有两种使用方法

  • UIView [begin commit]模式
//动画开始标记
[UIView beginAnimations:@"changeframe" context:nil];
//动画持续时间
[UIView setAnimationDuration:2.0];
//动画的代理对象
[UIView setAnimationDelegate:self];
//设置动画将开始时代理对象执行的SEL
[UIView setAnimationWillStartSelector:nil];
//设置动画结束时代理对象执行的SEL
[UIView setAnimationDidStopSelector:nil];
//设置动画延迟执行的时间
[UIView setAnimationDelay:1.0];
//设置动画的重复次数
[UIView setAnimationRepeatCount:];
//设置动画的曲线
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
//设置动画是否继续执行相反的动画
//[UIView setAnimationRepeatAutoreverses:YES];
_aniView.frame = CGRectMake(SCREEN_WIDTH-, SCREEN_HEIGHT/, , );
//结束动画标记
[UIView commitAnimations];

  • UIView Block调用

先举个Spring动画的例子

[UIView animateWithDuration:2.0//动画持续时间
delay:1.0//动画延迟执行的时间
usingSpringWithDamping:0.5//震动效果,范围0~1,数值越小震动效果越明显
initialSpringVelocity:2.0//初始速度,数值越大初始速度越快
options:UIViewAnimationOptionCurveEaseInOut//动画的过渡效果
animations:^{
//执行的动画
_aniView.frame = CGRectMake(SCREEN_WIDTH-, SCREEN_HEIGHT/, , );
}
completion:^(BOOL finished) {
//动画执行完毕后的操作
}];

Spring动画的看懂了,下面这几个肯定就没问题了

    [UIView animateWithDuration:(NSTimeInterval) //动画持续时间 animations:^{ //执行的动画 }];

    [UIView animateWithDuration:(NSTimeInterval) //动画持续时间 animations:^{ //执行的动画 } completion:^(BOOL finished) { //动画执行完毕后的操作 }];

    [UIView animateWithDuration:(NSTimeInterval) //动画持续时间 delay:(NSTimeInterval) //动画延迟执行的时间 options:(UIViewAnimationOptions) //动画的过渡效果 animations:^{ //执行的动画 } completion:^(BOOL finished) { //动画执行完毕后的操作 }];

两种使用方法介绍完了,再看下刚才没提到的动画

  • Keyframes关键帧动画

有时候我们需要实现多个连续的动画,或许我们可以在 completion中来实现多个动画的连续,但是我们却可以有更好的选择,那就是 Keyframe Animations(帧动画)。
举个例子:

[UIView animateKeyframesWithDuration:5.0 //所有动画完成的总时间
delay:1.0 //延迟执行时间
options:UIViewKeyframeAnimationOptionBeginFromCurrentState //枚举类型 UIViewKeyFrameAnimationOptions
animations:^{ //在这里添加动画
[UIView addKeyframeWithRelativeStartTime:0.0 //指相对于全部动画时间的开始时间。比如总时间为10s,设值为0.0,则此动画就是第0秒开始。取值都在0~1.0之间。
relativeDuration:0.25 //指相对于全部动画时间的持续时间。比如总时间为10秒,设置为0.25,则此动画所持续的时间就是2.5秒。取值都在0~1.0之间
animations:^{
_aniView.backgroundColor = [UIColor redColor];
}];
[UIView addKeyframeWithRelativeStartTime:0.1 relativeDuration:0.4 animations:^{
_aniView.transform = CGAffineTransformMakeRotation(M_PI_4);
}];
[UIView addKeyframeWithRelativeStartTime:0.25 relativeDuration:0.25 animations:^{
_aniView.backgroundColor = [UIColor yellowColor];
}];
[UIView addKeyframeWithRelativeStartTime:0.51 relativeDuration:0.01 animations:^{
_aniView.transform = CGAffineTransformIdentity;
}];
[UIView addKeyframeWithRelativeStartTime:0.55 relativeDuration:0.45 animations:^{
_aniView.backgroundColor = [UIColor greenColor];
}];
} completion:^(BOOL finished) {//这个动画执行完成后会执行这里
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)( * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
//两秒之后重复执行动画
[self buttonClick3:button];
});
}];

  • CATransition动画

用于做过渡动画或者转场动画,能够为层提供移出屏幕和移入屏幕的动画效果。
举个例子:
1.单个视图的过渡效果

[UIView transitionWithView:_aniView duration:1.5 options:UIViewAnimationOptionTransitionFlipFromTop|UIViewAnimationOptionOverrideInheritedOptions animations:^{
_aniView.backgroundColor = [UIColor blueColor];
} completion:^(BOOL finished) {
NSLog(@"动画结束");
}];

2.从旧视图转到新视图的动画效果

UIImageView * newImageView = [[UIImageView alloc]initWithFrame:_aniView.frame];
newImageView.image = [UIImage imageNamed:@"xinqin-paopao"];
[UIView transitionFromView:_aniView toView:newImageView duration:1.0 options:UIViewAnimationOptionTransitionFlipFromRight completion:^(BOOL finished) {
NSLog(@"动画结束");
}];

常用的大概就这么多,也比较简单,关于动画的过渡效果有很多枚举值,适合看代码直接动手尝试来学习.

快速上手UIView动画的更多相关文章

  1. [Android开发学iOS系列] 快速上手UIKit

    快速上手iOS UIKit UIKit是苹果官方的framework, 其中包含了各种UI组件, window和view, 事件处理, 交互, 动画, 资源管理等基础设施支持. 按照前面的介绍, 用U ...

  2. Netron开发快速上手(一):GraphControl,Shape,Connector和Connection

    版权所有,引用请注明出处:<<http://www.cnblogs.com/dragon/p/5203663.html >> 本文所用示例下载FlowChart.zip 一个用 ...

  3. 快速上手RaphaelJS-Instant RaphaelJS Starter翻译(一)

       (目前发现一些文章被盗用的情况,我们将在每篇文章前面添加原文地址,本文源地址:http://www.cnblogs.com/idealer3d/p/Instant_RaphaelJS_Start ...

  4. UnityShader快速上手指南(二)

    简介 前一篇介绍了如果编写最基本的shader,接下来本文将会简单的深入一下,我们先来看下效果吧 呃,gif效果不好,实际效果是很平滑的动态过渡 实现思路 1.首先我们要实现一个彩色方块 2.让色彩动 ...

  5. 快速上手最棒的网格框架ag-Grid

    由于对aggrid由衷的感谢, 又忍不住写了一篇软文来推广它(其实主要是为了弥补我把enterprise版扣下来后内心的愧疚...) ag-Grid是速度最快,功能最丰富的JavaScript dat ...

  6. 快速上手 Echarts

    最近使用到了 百度的 Echarts 数据可视化工具,这里简单介绍如何快速上手. 一.下载 这里选择目前最新版本,4.2.1 地址:https://github.com/apache/incubato ...

  7. [Swift通天遁地]八、媒体与动画-(8)使用开源类库快速实现位移动画

    ★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★➤微信公众号:山青咏芝(shanqingyongzhi)➤博客园地址:山青咏芝(https://www.cnblogs. ...

  8. 分享《Python 游戏编程快速上手(第3版)》高清中文版PDF+高清英文版PDF+源代码

    通过编写一个个小巧.有趣的游戏来学习Python,通过实例来解释编程的原理的方式.14个游戏程序和示例,介绍了Python基础知识.数据类型.函数.流程控制.程序调试.流程图设计.字符串操作.列表和字 ...

  9. 【转】Vue.js 2.0 快速上手精华梳理

    Vue.js 2.0 快速上手精华梳理 Sandy 发掘代码技巧:公众号:daimajiqiao 自从Vue2.0发布后,Vue就成了前端领域的热门话题,github也突破了三万的star,那么对于新 ...

随机推荐

  1. 使用openssl生成密钥、加密和签名

    openssl genrsa -out rsakey.pem 1024  //生成1024bit的RSA密钥,并保存到rsakey.pem,此处未对密钥进行加密 openssl genrsa -aes ...

  2. 【iOS微博客户端开发】1、微博整体项目的构建

    回顾自己做过的项目,总结里面的知识点,分享自己参照WXHL的视频开发的一个模拟微博客户端的过程,为了还在IOS上找不到项目参考的朋友,这里会由一系列手把手的教程,如有不足,还希望可以抖抖小手,献上您宝 ...

  3. 【java】java中直接根据Date 获取明天的时间

    展示代码: @Test public void dateTest(){ Date now = new Date(); System.out.println(now); // java.util.Dat ...

  4. js 的 slice方法

    slice() 方法可从已有的数组中返回选定的元素. string.slice( beginslice [, endSlice] ); 下面是参数的详细信息: beginSlice : 从零开始的索引 ...

  5. leetcode第一刷_Edit Distance

    最小编辑距离.非常经典的问题.今年微软实习生的笔试有一个这个的扩展版,牵扯到模板之类的,当时一行代码也没写出来. . dp能够非常优雅的解决问题.状态转移方程也非常明白.用pos[i][j]表示wor ...

  6. postprocessing stack v2

    用了v2和unity2017.3.0f有兼容性问题 在assetbundle的情况下 CopyStd这个shader打不进去 在assetbundle的menafest里面有列但是shader.fin ...

  7. sublime 插件cssrem安装及配置

    CSSREM CSSREM 是一个CSS的 px 值转 rem 值的Sublime Text3自动完成插件.先来看看插件的效果: 一个CSS的px值转rem值的Sublime Text 3自动完成插件 ...

  8. 蓝点通用管理系统V13版发布了!

    蓝点通用管理系统13版已发布! 重磅新功能:系统的通知和提醒功能,增加微信方式,微信通知.微信查询数据.微信拍照上传....... 蓝点的客户管理系统.进销存管理系统.产品管理系统.工作流管理系统.投 ...

  9. WPF动画制作简单的按钮动画

    主界面的代码 <StackPanel ButtonBase.Click="Grid_Click"> <Button Content="逐渐变大缩小&qu ...

  10. JS里取前天,昨天和今天

    var today=new Date(); var yesterday=new Date(today.getTime()-1000*60*60*24); var thedaybeforeyesterd ...