ios 动画效果CATransition笔记

初学ios开发,很多概念还不清楚,所以只有边学边做例子。又怕学了后面忘了前面,因此用自己的博客来纪录自己的学习历程,也是对自己学习不要懈怠做个监督。

刚学ios做动画效果。因为ios封装得很好,实现ios的漂亮动画效果也很简单,却因为我自己的粗心落了一个字母 导致纠结了一天,这个教训必须记住,同时也懂得了调试技能在编程里地位也是非常重要的存在。

实现ios动画有两种方法:一种UIView层面的,一种是使用CATransition.

[objc] view plaincopy

  1. - (void)viewDidLoad
  2. {
  3. [super viewDidLoad];
  4. // Do any additional setup after loading the view.
  5. UIView *redView = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
  6. redView.backgroundColor = [UIColor redColor];
  7. [self.view addSubview:redView];
  8. UIView *yellowView = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
  9. yellowView.backgroundColor = [UIColor yellowColor];
  10. [self.view addSubview:yellowView];
  11. UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
  12. [button setTitle:@"改变1" forState:UIControlStateNormal];
  13. button.frame = CGRectMake(10, 10, 300, 40);
  14. [button addTarget:self action:@selector(changeUIView1) forControlEvents:UIControlEventTouchUpInside];
  15. [self.view addSubview:button];
  16. UIButton *button2 = [UIButton buttonWithType:UIButtonTypeRoundedRect];
  17. [button2 setTitle:@"改变2" forState:UIControlStateNormal];
  18. button2.frame = CGRectMake(10, 120, 300, 40);
  19. [button2 addTarget:self action:@selector(changeUIView2) forControlEvents:UIControlEventTouchUpInside];
  20. [self.view addSubview:button2];
  21. }
  22. -(void) changeUIView1{
  23. [UIView beginAnimations:@"animation" context:nil];
  24. [UIView setAnimationDuration:1.0f];
  25. [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
  26. [UIView setAnimationTransition:UIViewAnimationTransitionCurlDown forView:self.view cache:YES];
  27. [self.view exchangeSubviewAtIndex:1 withSubviewAtIndex:0  ];
  28. [UIView commitAnimations];
  29. }
  30. -(void) changeUIView2{
  31. CATransition *transition = [CATransition animation];
  32. transition.delegate = self;
  33. transition.duration = 2.0f;
  34. transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn];
  35. transition.type = kCATransitionPush;
  36. transition.type = @"pageCurl"  ;//另一种设置动画效果方法
  37. transition.subtype = kCATransitionFromBottom;
  38. [self.view exchangeSubviewAtIndex:1 withSubviewAtIndex:0];
  39. [self.view.layer addAnimation:transition forKey:@"animation"];
  40. }

调用CATransition需要在frameworks中添加QuartzCore.framework,在.h文件中加入  #import <QuartzCore/QuartzCore.h>

setType:有四种类型:

kCATransitionFade                   //交叉淡化过渡

kCATransitionMoveIn               //移动覆盖原图

kCATransitionPush                    //新视图将旧视图推出去

kCATransitionReveal                //底部显出来

另一种设置方法

pageCurl     //向上翻一页

pageUnCurl   //向下翻一页

rippleEffect   //滴水效果

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

cube       //立方体效果

oglFlip      //上下翻转效果

setSubtype:有四种类型:

kCATransitionFromRight;

kCATransitionFromLeft(默认值)

kCATransitionFromTop;

kCATransitionFromBottom

时间: 2024-08-24 01:04:32

ios 动画效果CATransition笔记的相关文章

iOS动画效果和实现

动画效果提供了状态或页面转换时流畅的用户体验,在iOS系统中,咱们不需要自己编写绘制动画的代码,Core Animation提供了丰富的api来实现你需要的动画效果. UIKit只用UIView来展示动画,动画支持UIView下面的这些属性改变: frame bounds center transform alpha backgroundColor contentStretch 1.commitAnimations方式使用UIView动画 [cpp] view plain copy - (voi

IOS动画效果的实现

对于动画的使用,其实一直以来就不是很熟悉,因为平时使用的也少,使用也只是简单的使用.其实关于动画,一直在IOS中广泛存在.有时我们在调用某个方法时,经常会有一个参数Animation,填入BOOL参数,选择是否需要动画效果. 今天我就浅谈一下几种基本动画的实现. 首先为了测试动画效果,我随便声明了一个View. self.animationView = [[UIView alloc] initWithFrame:CGRectMake(50 , 100 , 100, 50)]; self.anim

ios 动画效果

转载:http://www.cnblogs.com/ludashi/p/4160208.html 一.封装动画方法 1.用CATransition实现动画的封装方法如下,每句代码是何意思,请看注释之. 1 #pragma CATransition动画实现 2 - (void) transitionWithType:(NSString *) type WithSubtype:(NSString *) subtype ForView : (UIView *) view 3 { 4 //创建CATra

iOS UIView动画效果 学习笔记

CGRect frame = _confirmV.frame; [UIView beginAnimations:nil context:nil];//动画定义开始 [UIView setAnimationDuration:0.5];//动画的时长 [UIView setAnimationDelay:0]; [UIView setAnimationDelegate:self]; [UIView setAnimationDidStopSelector:@selector(removeConfirmV

IOS开动画效果之──实现 pushViewController 默认动画效果

在开发中,视图切换会常常遇到,有时我们不是基于导航控制器的切换,但实际开发中,有时需要做成push效果,下面将如何实现push和pop 默认动画效果代码实例: 一.push默认动画效果 CATransition *transition = [CATransition animation]; transition.duration = 0.3f; transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMedia

IOS动画(Core Animation)总结 (参考多方文章)

一.简介 iOS 动画主要是指Core Animation框架.官方使用文档地址为:Core Animation Guide. Core Animation是IOS和OS X平台上负责图形渲染与动画的基础框架.Core Animation可以作用与动画视图或者其他可视元素,为你完成了动画所需的大部分绘帧工作.你只需要配置少量的动画参数(如开始点的位置和结束点的位置)即可使用Core Animation的动画效果.Core Animation将大部分实际的绘图任务交给了图形硬件来处理,图形硬件会加

(转)iOS动画Core Animation

文章转载:http://blog.sina.com.cn/s/blog_7b9d64af0101b8nh.html 在iOS中动画实现技术主要是:Core Animation. Core Animation负责所有的滚动.旋转.缩小和放大以及所有的iOS动画效果.其中UIKit类通常都有animated:参数部分,它可以允许是否使用动画. Core Animation主要是使用 我们知道每个UIView都关联到一个CALayer对象,CALayer是Core Animation中的图层. Cor

iOS动画和第三方插件学习网址

1.iOS动画效果 动画效果: https://dribbble.com/search?q=animation http://capptivate.co 网页动画十二原则: http://fortawesome.github.io/Font-Awesome/ 2.iOS开发中的第三方插件 ReaciveCocoa: http://blog.csdn.net/abc649395594/article/details/46123379  http://limboy.me/ios/2013/12/27

iOS动画入门一

一 动画介绍 在iOS中动画实现技术主要是:Core Animation. Core Animation负责所有的滚动.旋转.缩小和放大以及所有的iOS动画效果.其中UIKit类通常都有animated:参数部分,它可以允许是否使用动画. 本文将介绍UIView动画的实现方式,有基础方法和block方法. 二 实现方法 1 基础动画 [UIView beginAnimations:nil context:nil]; //动画开始 //Code... [UIView commitAnimation