文章转载:http://blog.sina.com.cn/s/blog_7b9d64af0101b8nh.html

在iOS中动画实现技术主要是:Core Animation。

Core Animation负责所有的滚动、旋转、缩小和放大以及所有的iOS动画效果。其中UIKit类通常都有animated:参数部分,它可以允许是否使用动画。

Core Animation主要是使用

我们知道每个UIView都关联到一个CALayer对象,CALayer是Core Animation中的图层。

Core Animation主要就是通过修改图层来改变UI的大小,位置,从而实现动画效果。

可以说,任何一个应用程序都离不开动画!

就连苹果各个UI控件中的切换操作,都有它内在的动画。

了解一下,关于动画的一些知识。

任何知识点,都会迁出一系列的知识点。

[UIView beginAnimations:@"dropDownloadLabel" context:UIGraphicsGetCurrentContext()];

[UIView setAnimationDuration: 0.5];

[UIView setAnimationBeginsFromCurrentState: NO];

// 执行的动画code

[UIView commitAnimations];

就将这段代码作为知识的切入点,开始了解吧。

[UIView beginAnimations:@"dropDownloadLabel" context:UIGraphicsGetCurrentContext()];

[UIView commitAnimations];

这两句代码,标记了一个动画的开始和结束。在中间我们可以写我们的一些动画操作!

beginAnimations方法

+ (void)beginAnimations:(NSString *)animationID context:(void *)context

用来,表示动画的开始。

animationID:作为动画的标识

context:自定义的一些动画数据,这些数据将发送给动画的代理方法:setAnimationWillStartSelector:方法和setAnimationDidStopSelector:方法。

这个,参数,通常为nil。我们可以直接设置为nil。

这里,我们使用UIGraphicsGetCurrentContext();因为此方法默认也会返回nil。

该方法告诉系统,我们将开始动画。并且,在该方法后,我们可以通过setAnimationXXX(一系列方法)来设置我们进行的动画的一些参数。

完成动画后,调用commitAnimations方法来通知系统,动画结束。

至此,我们知道,就是设置动画的一些列参数的方法即setAnimationXXX方法。

[UIView setAnimationDuration: 0.5];

[UIView setAnimationBeginsFromCurrentState: NO];

动画是可以嵌套的。

[UIView beginAnimations:@"animation_1" context:UIGraphicsGetCurrentContext()];

// code1

[UIView beginAnimations:@"animation_2" context:UIGraphicsGetCurrentContext()];

// code2

[UIView commitAnimations];

[UIView commitAnimations];

如果我们为动画设置了,setAnimationWillStartSelector:方法和setAnimationDidStopSelector:方法。

那么当动画开始或者停止的时候,动画的animationID参数和context参数,会传递给setAnimationWillStartSelector:方法和setAnimationDidStopSelector:方法。

悲剧总是要发生的!

苹果API在最后的描述中,给了这么一句话:

Use of this method is discouraged in iOS 4.0 and later. You should use the block-based animation methods to specify your animations instead.

可见,在iOS 4.0 后,block语法,大大增多了。这种方式,是不建议的,需要我们使用block的方式。

于是,动画的block方式:

[UIView animateWithDuration:0.3f delay:0.0f options:UIViewAnimationOptionCurveLinear

animations:^{ // 执行的动画code}

completion:^(BOOL finished){

// 完成后执行code

}];

在尽量用block来完成动画,因为说不定啥时候,老的动画方式,将被废除。

到此,可以告一段落。但是,我想将这简单的动画代码,一查到底!

commitAnimations方法:

+ (void)commitAnimations

标记动画结束。与beginAnimations方法成对使用。

例如:

[UIView commitAnimations];

一系列的setAnimationXXX方法:

setAnimationDuration方法:

+ (void)setAnimationDuration:(NSTimeInterval)duration

设置动画持续时间(秒)

例如:

[UIView setAnimationDuration: 0.5];

setAnimationBeginsFromCurrentState方法

+ (void)setAnimationBeginsFromCurrentState:(BOOL)fromCurrentState

设置动画开始时的状态。

我们构想一个场景:一般,我们按下一个按钮,将会执行动画一次。

当YES时:当上一次动画正在执行中,那么当下一个动画开始时,上一次动画的当前状态将成为下一次动画的开始状态。

当NO时:当上一个动画正在执行中,那么当下一个动画开始时,上一次动画需要先恢复到完成时的状态,然后在开始执行下一次动画。

setAnimationStartDate方法

+ (void)setAnimationStartDate:(NSDate *)startTime

设置动画开始时间。

setAnimationDelay方法

+ (void)setAnimationDelay:(NSTimeInterval)delay

设置动画开始的延迟时间(秒

setAnimationCurve方法

+ (void)setAnimationCurve:(UIViewAnimationCurve)curve

设置动画的曲线方式(就是动画的总体变化的时间曲线:开始快最后慢,开始慢最后快,最后慢,均匀线性)。

curve参数如下:

typedef NS_ENUM(NSInteger, UIViewAnimationCurve) {

UIViewAnimationCurveEaseInOut,         // slow at beginning and end

UIViewAnimationCurveEaseIn,            // slow at beginning

UIViewAnimationCurveEaseOut,           // slow at end

UIViewAnimationCurveLinear

};

setAnimationRepeatCount方法

+ (void)setAnimationRepeatCount:(float)repeatCount

设置动画重复次数

setAnimationRepeatAutoreverses方法

+ (void)setAnimationRepeatAutoreverses:(BOOL)repeatAutoreverses

设置动画是否做一次反向的执行。

如果设置为YES:动画将执行:动画初始状态》动画》动画完成状态》动画》动画初始状态。

如果设置为NO:默认值

setAnimationsEnabled方法

+ (void)setAnimationsEnabled:(BOOL)enabled

设置动画是否可用!

YES:默认值。

NO:动画效果被禁用

注意:仅仅是动画是否可用,在动画中被改变的UI对象依然是起作用的。仅仅是动画效果被禁用了。

areAnimationsEnabled方法

+ (BOOL)areAnimationsEnabled

返回动画效果是否被禁用。

提倡使用block方式来进行更加多的,简洁的控制!

其实发现了,这篇博客已经有点长了!有点坏味道!

不过,回头看,既然开篇就提到了Core Animation!

苹果中,默认的的简单动画,可以用setAnimationXXX一类的方法。但是如果,要让动画更加美观,复杂,那我想就要考Core Animation了!

做个分割,以下了解Core Animation!

------------------------------------------------------------------------------------------------------------------------------------

先来个代码吧!

[_imgPic setImage:image];// 设置新的图片

CATransition *animation = [CATransition animation];

[animation setDuration:1.0];

[animation setFillMode:kCAFillModeForwards];

[animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut]];

[animation setType:@"rippleEffect"];// rippleEffect

[animation setSubtype:kCATransitionFromTop];

[_imgPic.layer addAnimation:animation forKey:nil];

一头茫然啊!

UIView和CATransition两种动画是什么关系?到底用哪一种呢?

一种是UIView层面的。

一种是使用CATransition进行更低层次的控制。

第一种是UIView,UIView方式可能在低层也是使用CATransition进行了封装,它只能用于一些简单的、常用的效果展现。

所以,两者,往往在需要复杂的动画,应该用CATransition吧。

(转)iOS动画Core Animation的更多相关文章

  1. iOS 核心动画 Core Animation浅谈

    代码地址如下:http://www.demodashi.com/demo/11603.html 前记 关于实现一个iOS动画,如果简单的,我们可以直接调用UIView的代码块来实现,虽然使用UIVie ...

  2. iOS开发之核心动画(Core Animation)

    1.概述 Core Animation是一组非常强大的动画处理API,使用它能做出非常炫丽的动画效果,而且往往是事半功倍,使用它需要先添加QuartzCore.framework和引入对应的框架< ...

  3. iOS开发 - Core Animation 核心动画

    Core Animation Core Animation.中文翻译为核心动画,它是一组很强大的动画处理API,使用它能做出很炫丽的动画效果.并且往往是事半功倍. 也就是说,使用少量的代码就能够实现很 ...

  4. iOS - Core Animation(核心动画)

    Core Animation,中文翻译为核心动画,它是一组非常强大的动画处理API,使用它能做出非常炫丽的动画效果,而且往往是事半功倍.也就是说,使用少量的代码就可以实现非常强大的功能.Core An ...

  5. iOS 图形图像动画 Core Animation

    //Core Animation #define WeakSelf __weak __typeof(self) weakSelf = self #define StrongSelf __strong ...

  6. 核心动画——Core Animation

    一. CALayer (一). CALayer简单介绍 在iOS中,你能看得见摸得着的东西基本上都是UIView,比方一个button.一个文本标签.一个文本输入框.一个图标等等.这些都是UIView ...

  7. IOS中的动画——Core Animation

    一.基础动画 CABasicAnimation //初始化方式 CABasicAnimation * cabase=[CABasicAnimation animation]; //通过keyPath设 ...

  8. 动画(Animation) 、 高级动画(Core Animation)

    1 演示UIImage制作的动画 1.1 问题 UIImage动画是IOS提供的最基本的动画,通常用于制作一些小型的动画,本案例使用UIImage制作一个小狗跑动的动画,如图-1所示: 图-1 1.2 ...

  9. Core Animation编程指南

    本文是<Core Animation Programming Guide>2013-01-28更新版本的译文.本文略去了原文中关于OS X平台上Core Animation相关内容.因为原 ...

随机推荐

  1. C#&Java重学笔记(集合比较和转换)

    C#部分: 1.C#中集合有三种,数组类,ArrayList,和字典键值对类,一般也可以自定义集合,但是自定义集合的类型也只有这三类. 2.自定义集合实现三类集合的方法:前两者需要继承Collecti ...

  2. POJ 2101

    #include <iostream> #include <algorithm> #include <cmath> using namespace std; int ...

  3. 通过HTTP头控制浏览器的缓存

    通过HTTP头控制浏览器的缓存 浏览器缓存是提高用户体验和提升程序性能的一个很重要的途径,通过浏览器的缓存控制,可以对实时性要求不高的数据进行缓存,可以减少甚至不需要再次对服务器的请求就可以显示数据. ...

  4. CodeIgniter 错误: In order to use the Session class you are required to set an encryption key

    CodeIgniter SESSION  第一次用 session 遇到这个错误 , 说是要加一个密钥才可以使用,加就加吧, 打开 config.php 找到以下代码 /*|------------- ...

  5. python--httplib模块使用

    httplib是一个相对底层的http请求模块,其上有专门的包装模块,如urllib内建模块,goto等第三方模块,但是封装的越高就越不灵 活,比如urllib模块里请求错误时就不会返回结果页的内容, ...

  6. php截取字符串中的关键字,并高亮显示

    <?php $str = "hahaceshi测试一下关键字高亮显示,以及长字符串截取的问题!"; $key = "关键字"; $r = sub_key_ ...

  7. 利用反射完成初级万能DAO

    一.目标 利用反射完成初级万能DAO 二.注意 1.Field[] fi = clazz.getDeclaredFields(); for(Field ff : fi){ ff.setAccessib ...

  8. JLINK V8 升级5.12E 在MDK5.20不变砖

    转载:只是用了新的固件,步骤跟原子提供的方法 是一模一样的.这边也把步骤写了上来. 使用 SAM-PROG 更新 JLINK 固件一 :安装软件 安装 Install AT91-ISP v1.13.e ...

  9. Android开发:彻底更改工程名

    对于已经建立的工程,如果发现原来的工程名不合适,此时若想彻底更改工程名,需要三个步骤: 1.更改工程名 选中工程名,右键-->Refactor-->Rename. 2.更改src文件下包名 ...

  10. 感知机(python实现)

    感知机(perceptron)是二分类的线性分类模型,输入为实例的特征向量,输出为实例的类别(取+1和-1).感知机对应于输入空间中将实例划分为两类的分离超平面.感知机旨在求出该超平面,为求得超平面导 ...