实现iphone漂亮的动画效果主要有两种方法,一种是UIView层面的,一种是使用CATransition进行更低层次的控制,

第一种是UIView,UIView方式可能在低层也是使用CATransition进行了封装,它只能用于一些简单的、常用的效果展现,这里写一个常用的示例代码,供大家参考。

viewplaincopy to clipboardprint?

1.[UIView beginAnimations:@"Curl"context:nil];//动画开始

2.[UIView setAnimationDuration:0.75];

3.[UIView setAnimationDelegate:self];

4.[UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:myview cache:YES];

5.[myview removeFromSuperview];

6.[UIView commitAnimations];

[UIViewbeginAnimations:@"Curl"context:nil];//动画开始[UIView setAnimationDuration:0.75];[UIView setAnimationDelegate:self];[UIViewsetAnimationTransition:UIViewAnimationTransitionCurlUp forView:myviewcache:YES];[myview removeFromSuperview];[UIView commitAnimations];

第二种方式相对复杂一些,但如果更好的进行控制,还是使用这种方法吧,基本使用方法可以看一下如下例子:

viewplaincopy to clipboardprint?

1.CATransition *animation = [CATransition animation];

2.[animation setDuration:1.25f];

3.[animation setTimingFunction:[CAMediaTimingFunction

4.functionWithName:kCAMediaTimingFunctionEaseIn]];

5.[animation setType:kCATransitionReveal];

6.[animation setSubtype: kCATransitionFromBottom];

7.[self.view.layer addAnimation:animation forKey:@"Reveal"];

CATransition*animation = [CATransition animation];[animation setDuration:1.25f];[animationsetTimingFunction:[CAMediaTimingFunctionfunctionWithName:kCAMediaTimingFunctionEaseIn]];[animationsetType:kCATransitionReveal];[animation setSubtype:kCATransitionFromBottom];[self.view.layer addAnimation:animationforKey:@"Reveal"];

这里使用了setType与setSubtype组合,这使用个比较保险,因为他的参数就是官方API里定义的,他们的参数说明可以参考如下:

viewplaincopy to clipboardprint?

1.setType:可以返回四种类型:

2.kCATransitionFade淡出

3.kCATransitionMoveIn覆盖原图

4.kCATransitionPush推出

5.kCATransitionReveal底部显出来

6.setSubtype:也可以有四种类型:

7.kCATransitionFromRight;

8.kCATransitionFromLeft(默认值)

9.kCATransitionFromTop;

10.        kCATransitionFromBottom

setType:可以返回四种类型:kCATransitionFade淡出kCATransitionMoveIn覆盖原图kCATransitionPush推出kCATransitionReveal底部显出来setSubtype:也可以有四种类型:kCATransitionFromRight;kCATransitionFromLeft(默认值)kCATransitionFromTop;kCATransitionFromBottom

还有一种设置动画类型的方法,不用setSubtype,只用setType

viewplaincopy to clipboardprint?

1.[animation setType:@"suckEffect"];

[animationsetType:@"suckEffect"];

这里的suckEffect就是效果名称,可以用的效果主要有:

viewplaincopy to clipboardprint?

1.pageCurl   向上翻一页

2.pageUnCurl 向下翻一页

3.rippleEffect 滴水效果

4.suckEffect 收缩效果,如一块布被抽走

5.cube 立方体效果

6.oglFlip 上下翻转效果

pageCurl  向上翻一页pageUnCurl 向下翻一页rippleEffect 滴水效果suckEffect 收缩效果,如一块布被抽走cube 立方体效果oglFlip上下翻转效果

最后再给出一种常用代码供大家参考。

viewplaincopy to clipboardprint?

1.// Curl the image up or down

2.CATransition *animation = [CATransition animation];

3.[animation setDuration:0.35];

4.[animation setTimingFunction:UIViewAnimationCurveEaseInOut];

5.if (!curled){

6.//animation.type = @"mapCurl";

7.animation.type = @"pageCurl";

8.animation.fillMode = kCAFillModeForwards;

9.animation.endProgress = 0.99;

10.        } else {

11.        //animation.type = @"mapUnCurl";

12.        animation.type = @"pageUnCurl";

13.        animation.fillMode = kCAFillModeBackwards;

14.        animation.startProgress = 0.01;

15.        }

16.        [animation setRemovedOnCompletion:NO];

17.        [view exchangeSubviewAtIndex:0 withSubviewAtIndex:1];

18.        [view addAnimation:animation forKey"pageCurlAnimation"];

19.        // Disable user interaction where necessary

20.        if (!curled) {

21.

22.        } else {

23.

24.        }

25.        curled = !curled;

// Curl the image up or downCATransition *animation =[CATransition animation];[animation setDuration:0.35];[animationsetTimingFunction:UIViewAnimationCurveEaseInOut];if (!curled){//animation.type= @"mapCurl";animation.type =@"pageCurl";animation.fillMode =kCAFillModeForwards;animation.endProgress = 0.99;} else {//animation.type =@"mapUnCurl";animation.type =@"pageUnCurl";animation.fillMode = kCAFillModeBackwards;animation.startProgress= 0.01;}[animation setRemovedOnCompletion:NO];[view exchangeSubviewAtIndex:0withSubviewAtIndex:1];[view addAnimation:animationforKey"pageCurlAnimation"];// Disable user interaction wherenecessaryif (!curled) { } else { }curled = !curled;

最新文章

  1. 高性能JavaScript--数据存储(简要学习笔记二)
  2. Java-String类的常用方法总结
  3. MVC项目实践,在三层架构下实现SportsStore-03,Ninject控制器工厂等
  4. java开发规范总结_代码编码规范
  5. iOS-#ifdef DEBUG代码块介绍
  6. Largest Rectangle in a Histogram(HDU 1506 动态规划)
  7. http GET
  8. 我的C++学习之旅
  9. C++模板入门教程(一)——模板概念与基本语法
  10. java基础(八)-----深入解析java四种访问权限
  11. Oracle数据库中OVER()函数的了解
  12. python第一百零七天-- Django 基础 2
  13. Confluence 6 针对 key "cp_" 或 "cps_" 的 "Duplicate Entry" 问题解决
  14. [js]js杂项陆续补充中...
  15. Gradle的介绍与安装
  16. 自学Zabbix之路15.1 Zabbix数据库表结构简单解析-Hosts表、Hosts_groups表、Interface表
  17. Python核心编程的四大神兽
  18. 为WinEdt自定义XeLatex快捷键
  19. RabbitMQ入门_11_DLX
  20. spring data jpa 的简单使用

热门文章

  1. wdatepicker默认时间为当前时间
  2. 026.Zabbix简单调优
  3. C++雾中风景10:聊聊左值,纯右值与将亡值
  4. python基础下的数据结构与算法之顺序表
  5. JAVA 类和对象基础知识详解
  6. MySQL DROP DB或TABLE场景下借助SQL Thread快速应用binlog恢复方案
  7. KVM基于X86硬件辅助的虚拟化技术实现机制【转】
  8. Codeforces Round #374 (Div. 2) A. One-dimensional Japanese Crosswor 水题
  9. 2013-2014 ACM-ICPC, NEERC, Southern Subregional Contest Problem B. Travelling Camera Problem set贪心
  10. java native方法与JNI实现