一、大小动画(改变frame)

-(void)changeFrame{
CGRect originalRect = self.anView.frame;
CGRect rect = CGRectMake(self.anView.frame.origin.x-, self.anView.frame.origin.y-, , );
[UIView animateWithDuration: animations:^{
self.anView.frame = rect;
} completion:^(BOOL finished) {
[UIView animateWithDuration: animations:^{
self.anView.frame = originalRect;
}];
}];
}

二、拉伸动画(改变bounds)

-(void)changeBounds{
CGRect originalBounds = self.anView.bounds;
//尽管这个rect的x,y跟原始的不同,动画也只是改变了宽高
CGRect rect = CGRectMake(, , , );
[UIView animateWithDuration: animations:^{
self.anView.bounds = rect;
} completion:^(BOOL finished) {
[UIView animateWithDuration: animations:^{
self.anView.bounds = originalBounds;
}];
}];
}

三、转移动画(改变center)

-(void)changeCenter{
CGPoint originalPoint = self.anView.center;
CGPoint point = CGPointMake(self.anView.center.x, self.anView.center.y-);
[UIView animateWithDuration:0.3 animations:^{
self.anView.center = point;
} completion:^(BOOL finished) {
[UIView animateWithDuration: animations:^{
self.anView.center = originalPoint;
}];
}];
}

四、旋转动画(改变transform)

-(void)transform{
CGAffineTransform originalTransform = self.anView.transform;
[UIView animateWithDuration: animations:^{
//self.anView.transform = CGAffineTransformMakeScale(0.6, 0.6);//缩放
//self.anView.transform = CGAffineTransformMakeTranslation(60, -60);
self.anView.transform = CGAffineTransformMakeRotation(4.0f);
} completion:^(BOOL finished) {
[UIView animateWithDuration: animations:^{
self.anView.transform = originalTransform;
}];
}];
}

五、透明度动画(改变alpha)

-(void)alpha{
[UIView animateWithDuration: animations:^{
self.anView.alpha = 0.3;
} completion:^(BOOL finished) {
[UIView animateWithDuration: animations:^{
self.anView.alpha = ;
}];
}];
}

六、背景颜色Keyframes动画(改变background)

-(void)changeBackground{
[UIView animateKeyframesWithDuration:9.0 delay:.f options:UIViewKeyframeAnimationOptionCalculationModeLinear animations:^{
[UIView addKeyframeWithRelativeStartTime:.f relativeDuration:1.0 / animations:^{
self.anView.backgroundColor = [UIColor colorWithRed:0.9475 green:0.1921 blue:0.1746 alpha:1.0];
}];
[UIView addKeyframeWithRelativeStartTime:1.0 / relativeDuration:1.0 / animations:^{
self.anView.backgroundColor = [UIColor colorWithRed:0.1064 green:0.6052 blue:0.0334 alpha:1.0];
}];
[UIView addKeyframeWithRelativeStartTime:2.0 / relativeDuration:1.0 / animations:^{
self.anView.backgroundColor = [UIColor colorWithRed:0.1366 green:0.3017 blue:0.8411 alpha:1.0];
}];
[UIView addKeyframeWithRelativeStartTime:3.0 / relativeDuration:1.0 / animations:^{
self.anView.backgroundColor = [UIColor colorWithRed:0.619 green:0.037 blue:0.6719 alpha:1.0];
}];
[UIView addKeyframeWithRelativeStartTime:3.0 / relativeDuration:1.0 / animations:^{
self.anView.backgroundColor = [UIColor whiteColor];
}];
} completion:^(BOOL finished) {
NSLog(@"动画结束");
}];
}

七、Spring动画(iOS7.0起)

-(void)springAnimation{
CGRect originalRect = self.anView.frame;
CGRect rect = CGRectMake(self.anView.frame.origin.x-, self.anView.frame.origin.y, , );
[UIView animateWithDuration:0.4 delay: usingSpringWithDamping:0.5 initialSpringVelocity: options:UIViewAnimationOptionCurveLinear animations:^{
self.anView.frame = rect;
} completion:^(BOOL finished) {
[UIView animateWithDuration: delay: usingSpringWithDamping:0.5 initialSpringVelocity: options:UIViewAnimationOptionCurveLinear animations:^{
self.anView.frame = originalRect;
} completion:^(BOOL finished) {
}];
}];
}

八、transition动画

-(void)transitionAnimation{
[UIView transitionWithView:self.anView duration:2.0 options:UIViewAnimationOptionTransitionFlipFromLeft animations:^{
//self.anView.backgroundColor = [UIColor blueColor];
} completion:^(BOOL finished) {
[UIView transitionWithView:self.anView duration:2.0 options:UIViewAnimationOptionTransitionFlipFromRight animations:^{
//self.anView.backgroundColor = [UIColor greenColor];
} completion:^(BOOL finished) {
}];
}];
}

九、关于参数option选择说明

1.UIViewAnimationOptions

UIViewAnimationOptionLayoutSubviews            //进行动画时布局子控件

UIViewAnimationOptionAllowUserInteraction      //进行动画时允许用户交互

UIViewAnimationOptionBeginFromCurrentState     //从当前状态开始动画

UIViewAnimationOptionRepeat                    //无限重复执行动画

UIViewAnimationOptionAutoreverse               //执行动画回路

UIViewAnimationOptionOverrideInheritedDuration //忽略嵌套动画的执行时间设置

UIViewAnimationOptionOverrideInheritedCurve    //忽略嵌套动画的曲线设置

UIViewAnimationOptionAllowAnimatedContent      //转场:进行动画时重绘视图

UIViewAnimationOptionShowHideTransitionViews   //转场:移除(添加和移除图层的)动画效果

UIViewAnimationOptionOverrideInheritedOptions  //不继承父动画设置

UIViewAnimationOptionCurveEaseInOut            //时间曲线,慢进慢出(默认值)

UIViewAnimationOptionCurveEaseIn               //时间曲线,慢进

UIViewAnimationOptionCurveEaseOut              //时间曲线,慢出

UIViewAnimationOptionCurveLinear               //时间曲线,匀速

UIViewAnimationOptionTransitionNone            //转场,不使用动画

UIViewAnimationOptionTransitionFlipFromLeft    //转场,从左向右旋转翻页

UIViewAnimationOptionTransitionFlipFromRight   //转场,从右向左旋转翻页

UIViewAnimationOptionTransitionCurlUp          //转场,下往上卷曲翻页

UIViewAnimationOptionTransitionCurlDown        //转场,从上往下卷曲翻页

UIViewAnimationOptionTransitionCrossDissolve   //转场,交叉消失和出现

UIViewAnimationOptionTransitionFlipFromTop     //转场,从上向下旋转翻页

UIViewAnimationOptionTransitionFlipFromBottom  //转场,从下向上旋转翻页

2.UIViewKeyframeAnimationOptions

UIViewAnimationOptionLayoutSubviews           //进行动画时布局子控件

UIViewAnimationOptionAllowUserInteraction     //进行动画时允许用户交互

UIViewAnimationOptionBeginFromCurrentState    //从当前状态开始动画

UIViewAnimationOptionRepeat                   //无限重复执行动画

UIViewAnimationOptionAutoreverse              //执行动画回路

UIViewAnimationOptionOverrideInheritedDuration //忽略嵌套动画的执行时间设置

UIViewAnimationOptionOverrideInheritedOptions //不继承父动画设置

UIViewKeyframeAnimationOptionCalculationModeLinear     //运算模式 :连续

UIViewKeyframeAnimationOptionCalculationModeDiscrete   //运算模式 :离散

UIViewKeyframeAnimationOptionCalculationModePaced      //运算模式 :均匀执行

UIViewKeyframeAnimationOptionCalculationModeCubic      //运算模式 :平滑

UIViewKeyframeAnimationOptionCalculationModeCubicPaced //运算模式 :平滑均匀

就UIView的动画而言,UIViewKeyframeAnimationOptions紧在Keyframes,其余的都是UIViewAnimationOptions。

十、总结和扩展

1.UIView动画主要是变化UIView的自带属性

2.UIView动画可以有很多种方式实现同一效果

3.Spring动画iOS7.0以上才有

4.UIViewKeyframeAnimationOptions用着Keyframes动画,其余都用UIViewAnimationOptions枚举

十一、源码地址

https://github.com/minggo620/iOSViewAnimation

谈UIView Animation编程艺术的更多相关文章

  1. 浅谈JavaScript DOM编程艺术读后感和一点总结

    最近工作不是很忙就想想想JavaScript的内部组成和一些要点,就是从这本书开始的.对新手来说还好,简单易懂. 简单终结下我重书中学到的一些要点. 下面都是个人学习的要点提取: 1.给自己预留退路, ...

  2. 转一篇简洁的UIView动画编程方法

    iOS  中的 UIView 动画编程其实还是很简单的,像 CSS3 一样,在给定的时间内完成状态连续性的变化呈现.比如背景色,Frame 大小,位移.翻转,特明度等. 以前我使用的编程方式都是用下面 ...

  3. 程序员编程艺术第三十六~三十七章、搜索智能提示suggestion,附近点搜索

    第三十六~三十七章.搜索智能提示suggestion,附近地点搜索 作者:July.致谢:caopengcs.胡果果.时间:二零一三年九月七日. 题记 写博的近三年,整理了太多太多的笔试面试题,如微软 ...

  4. Objective-C 编程艺术 (Zen and the Art of the Objective-C Craftsmanship 中文翻译)

    # 禅与 Objective-C 编程艺术 (Zen and the Art of the Objective-C Craftsmanship 中文翻译) - 原文 <https://githu ...

  5. [Objective-C]编程艺术 笔记整理

    看了<禅与 Objective-C 编程艺术>,发现不少平时不注意的或注意但没有系统总结的东西,特此记录一下. 这次没有整理完,后续更新会结合手里的一些其他资料整理. 新博客wossone ...

  6. 读书笔记:JavaScript DOM 编程艺术(第二版)

    读完还是能学到很多的基础知识,这里记录下,方便回顾与及时查阅. 内容也有自己的一些补充. JavaScript DOM 编程艺术(第二版) 1.JavaScript简史 JavaScript由Nets ...

  7. JavaScript DOM 编程艺术·setInterval与setTimeout的动画实现解析

    先贴上moveElement()函数的大纲,为了方便观看,删了部分代码,完整版粘到文章后面. function moveElement(elementID,final_x,final_y,interv ...

  8. 转《UNIX编程艺术》读书心得

    花了一段时间看完了<UNIX编程艺术>,但不是看得特别仔细,尤其是后面作者通过对工具的讲解来阐述其设计思想,因为很多工具能未曾接触过,难免就会产生一些乏味的感觉.其实就像译者姜宏在译序里说 ...

  9. 读《UNIX编程艺术》一感

    我记得早在2006年的时候就开始频繁使用awk做文本处理方面的工作,07年的时候周围有人用perl,我还感到很不解,觉得写得很复杂,没有awk one liner 那么方便和神奇.一直在了解awk的具 ...

随机推荐

  1. 大数据开发实战:离线大数据处理的主要技术--Hive,概念,SQL,Hive数据库

    1.Hive出现背景 Hive是Facebook开发并贡献给Hadoop开源社区的.它是建立在Hadoop体系架构上的一层SQL抽象,使得数据相关人员使用他们最为熟悉的SQL语言就可以进行海量数据的处 ...

  2. Laravel 5.5 使用 Jwt-Auth 实现 API 用户认证以及刷新访问令牌

    最近在做一个公司的项目,前端使用 Vue.js,后端使用 Laravel 构建 Api 服务,用户认证的包本来是想用 Laravel Passport 的,但是感觉有点麻烦,于是使用了 jwt-aut ...

  3. Android -- AudioPlayer

    AudioPlayer 主要是实现边录边播(AudioRecord+AudioTrack)以及对音频的实时处理(如会说话的汤姆猫.语音) 优点:语音的实时处理,可以用代码实现各种音频的封装 缺点:输出 ...

  4. POJ 1265 pick定理

    pick公式:多边形的面积=多边形边上的格点数目/2+多边形内部的格点数目-1. 多边形边上的格点数目可以枚举每条边求出.如果是水平或者垂直,显然可以得到,否则则是坐标差的最大公约数减1.(注这里是不 ...

  5. 【图片识别】java 图片文字识别 ocr (转)

    http://www.cnblogs.com/inkflower/p/6642264.html 最近在开发的时候需要识别图片中的一些文字,网上找了相关资料之后,发现google有一个离线的工具,以下为 ...

  6. dubbo Framework pic

    dubbo Framework pic

  7. Android改动包名称规范方法

    第一步.在项目上右键,选择android tools->rename application package,输入须要改为的名称,然后选择须要替换的文件里的包名.这里仅改动了project中包括 ...

  8. Android 事件模型

    本文内容 基于监听的事件模型 基于回调的事件模型 Android 支持两种事件模型,基于监听的事件模型和基于回调的事件模型. 基于监听的事件模型 基于监听的事件模型是一种委托式的,更"面向对 ...

  9. Android Studio 之 导入Eclipse项目常见问题及解决方案

    在将Eclipse做的Android项目成功导入Android Studio 后,启动生成,遇到一些问题,现总结如下: 问题1:图片命名问题 AS对图片命名要求比eclipse严格,图片名称只能有&q ...

  10. MVC 之 缓存机制(二)

    八.应用程序缓存 应用程序缓存提供了一种编程方式,可通过键/值对将任意数据存储在内存中. 使用应用程序缓存与使用应用程序状态类似. 但是,与应用程序状态不同的是,应用程序缓存中的数据是易失的, 即数据 ...