转载自:http://blog.csdn.net/ronaldo_carry/article/details/49070119

将viewdidload里面的代码全部注释掉

- (void)viewDidLoad {

[superviewDidLoad];

}

重写点击交换的事件方法

//交换视图

- (IBAction)changeBtn {

//通过类方法来创建转场动画

CATransition *transition = [CATransitionanimation];

transition.duration = 1.0f;//动画的间隔为1S

//设置动画的变化方法

transition.timingFunction = [CAMediaTimingFunctionfunctionWithName:kCAMediaTimingFunctionEaseInEaseOut];

//下面是交换视图特有的属性

//私有API 使用私有API的时候要慎重(这个是苹果官网承认的)

transition.type = @"pageCurl";

//    transition.type =@"fade";fade渐隐

//type的子类型 转换的方向

transition.subtype =  @"fromRight";

//    //这里也可以写成这样 效果是一样的

//    transition.subtype = kCATransitionFromRight;

//设置具体的动画 交换两个视图的位置

[_aninmationViewexchangeSubviewAtIndex:0withSubviewAtIndex:1];

//给图层添加动画

[_aninmationView.layeraddAnimation:transitionforKey:@"myAnimation"];

}

 

这样运行出来的效果是  点击了交换按钮  出来动画翻页效果  但是始终展现的是最上面的view 并不会实现预期的交换两个view的效果

查看了一下这个函数的官方文档

- (void)addAnimation:(CAAnimation *)anim forKey:(nullableNSString *)key;

我们可以看到文档中是这么解释的:

/** Animation methods. **/

/* Attach an animation object to the layer. Typically this is implicitly

* invoked through an action that is an CAAnimation object.

*

* 'key' may be any string such that only one animation per unique key

* is added per layer. The special key 'transition' is automatically

* used for transition animations. The nil pointer is also a valid key.

*

* If the `duration' property of the animation is zero or negative it

* is given the default duration, either the value of the

* `animationDuration' transaction property or .25 seconds otherwise.

*

* The animation is copied before being added to the layer, so any

* subsequent modifications to `anim' will have no affect unless it is

* added to another layer. */

 

翻译过来就是:

/** Animation methods. **/  动画方法

/* 给图层(layer)附加上一个动画对象  通常这是隐式的通过一个动作,这个动作是一个CAAnimation对象来调用.

* 'key'键可能是任意的string,这样每个唯一的键只有一个动画(animation)被添加到图层(layer)中.特殊的键'transition'会被自动用于转场动画中,空指针同样也是一个空的键值.

*如果动画的持续时间(duration)属性是0或者负,则给定默认时间,或者是转换属性`animationDuration'的值,否则的话0.25S.

* 动画(animation)被添加到图层(layer)之前已经被复制(copied),所以任何后续对'anim'动画修改都不会有影响,除非它被添加到另一个图层(layer)中   /*这句话有点郁闷 没怎么理解他说的意思*/

**/

组动画:

-(void)animationGroup{

CAAnimationGroup *animG = [CAAnimationGroup animation];

//2.添加动画到动画数组animation groups中

animG.animations  = @[anim1,anim2];

//4.添加动画到图层上

[self.navigationController.view.layer addAnimation:animG forKey:@"animG"];

}

然后就会依次执行组动画里的动画了

- (void)addAnimation:(CAAnimation *)anim forKey:(nullable NSString *)key; 方法浅析的更多相关文章

  1. KVC之-(id)valueForKey:(NSString *)key的实现原理与验证

    KVC之-(id)valueForKey:(NSString *)key的实现原理与验证 2.-(id)valueForKey:(NSString *)key的实现原理与验证; #功能:使用一个字符串 ...

  2. iOS UIAlertController跟AlertView用法一样 && otherButtonTitles:(nullable NSString *)otherButtonTitles, ... 写法

    今天写弹出框UIAlertController,用alertView习惯了,所以封装了一下,跟alertView用法一样,不说了,直接上代码: 先来了解一下otherButtonTitles:(nul ...

  3. Java基础-接口.编写2个接口:InterfaceA和InterfaceB;在接口InterfaceA中有个方法void printCapitalLetter();在接口InterfaceB中有个方法void printLowercaseLetter();然 后写一个类Print实现接口InterfaceA和InterfaceB,要求 方法 实现输出大写英文字母表的功能,printLowerca

    #34.编写2个接口:InterfaceA和InterfaceB:在接口InterfaceA中有个方法void printCapitalLetter():在接口InterfaceB中有个方法void ...

  4. OC特有语法:分类category,给NSString增加方法计算字符串中数字的个数

    1:分类的使用场景:想对一个类,扩充一些功能,而又不改变原来类的模型,也不用继承,这时OC中的特有语法:分类可以做到: 当然分类也是一个类,也需要声明和实现,声明在.h文件中,实现在.m文件中,格式如 ...

  5. Memcache 查看列出所有key方法

    参考博文: Memcache 查看列出所有key方法 1. cmd上登录memcache telnet 127.0.0.1 11211  2. 列出所有keys stats items // 这条是命 ...

  6. 简易搭建git仓库、关联远程和本地仓库方法。克隆仓库方法。同一台电脑上创建两个git ssh key方法。

    一,在github上建仓库 react-js-antd-demo: 二:将远程仓库与本地仓库关联 git remote add origin git@github.com:begin256/react ...

  7. Memcache查看列出所有key方法

    Memcached查看列出所有key方法 测试的过程中,发现Memcached没有一个比较简单的方法可以直接象redis那样keys *列出所有的Session key,并根据key get对应的se ...

  8. - (BOOL)setResourceValue:(id)value forKey:(NSString *)key error:(NSError **)error

    如果我们的APP需要存放比较大的文件的时候,同时又不希望被系统清理掉,那我么我们就需要把我们的资源保存在Documents目录下,但是我们又不希望他会被iCloud备份,因此就有了这个方法 [URL ...

  9. iOS 发大招 otherButtonTitles:(nullable NSString *)otherButtonTitles, ... 写法 && 编写通用类的时候关于可变参数的处理

    开始 我  以为 这个 alertView 里面 ...的写法  应该 是一个 普通的数组  然 并没有 分享一篇好文 http://www.tekuba.net/program/290/ IOS实现 ...

随机推荐

  1. Django的使用

    Django使用介绍 1.MTV Django中的MTV分别表示models.templates和views. models文件主要定义数据库的连接. templates文件可以放一些html的模版. ...

  2. 2015 ACM/ICPC Asia Regional Changchun Online

    1001 Alisha’s Party 比赛的时候学长stl吃T.手写堆过. 赛后我贴了那两份代码都过.相差.2s. 于是用stl写水果. # include <iostream> # i ...

  3. SQL Server 2012中快速插入批量数据的示例及疑惑

    SQL Server 2008中SQL应用系列--目录索引 今天在做一个案例演示时,在SQL Server 2012中使用Insert语句插入1万条数据,结果遇到了一个奇怪的现象,现将过程分享出来,以 ...

  4. Session和Cookie的使用总结

    Session和Cookie的使用总结: Session和cookie都是asp.Net中的内置对象,至于他们有什么区别,在这里就不在多说,现在来说说一些比较实用点的东西: 我们知道网站都有一个后台管 ...

  5. px和em,rem的区别

    任意浏览器的默认字体高都是16px. px: 像素(Pixel) , 计算机屏幕上的一个点.固定大小:不方便维护: em:相对于当前对象内 (父元素) 文本的字体尺寸.如当前对行内文本的字体尺寸未被人 ...

  6. Access to the path "Library\UnityAssemblies\UnityEngine.xml" is denied.

    这个问题基本上是重新打开UnityEditor,导入工程的时候VisualStudio还开着导致的. 解决方法是关掉Visual Studio,再重新打开.

  7. 安装Eclipse环境

    1.下载安装JDK,并设置环境变量 2.下载Eclipse,官网下载地址:http://www.eclipse.org/downloads/ 选择相应版本,我选的是Windows 64bit 3.下载 ...

  8. BaLaBaLa

    #include<cstdio>#include<cstring>#include<cmath>#include<queue>#include<a ...

  9. hdu_3709_Balanced Number(数位DP)

    题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=3709 题意:给你一个区间,让你找平衡数的个数 题解:设dp[i][j][k]为前i位以第j位为支撑点的 ...

  10. Number-guessing Game

    Number-guessing Game Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 131072/65536K (Java/Othe ...