UIViewAnimation动画与CATransition类动画

来源:互联网 发布:价格标签打印软件 编辑:程序博客网 时间:2024/06/06 00:53

CATransition is an Objective-C wrapper for creating view transitions. As of 3.1.2, there are 11 types of transitions. 4 of them are SDK-compatible, but are the most boring ones. The following shows all 11 types of transition from picture "A" to "B" at 40%. The subtypes, if any, is "fromLeft".

cameraIris

cube

fade (kCATransitionFade)

moveIn (kCATransitionMoveIn)

oglFlip

pageCurl

pageUnCurl

push (kCATransitionPush)

reveal (kCATransitionReveal)

rippleEffect

suckEffect

subtype and filter

Many transitions have are further divided into several discrete subtypes. They often control the movement direction of the animation.

Some transitions accept addition arguments through the filter property, for example, you can set the location of suckEffect using

...CAFilter* filter = [CAFilter filterWithName:@"suckEffect"];[filter setValue:[NSValue valueWithCGPoint:CGPointMake(160, 240)] forKey:@"inputPosition"];transition.filter = filter;...
TransitionSubtypesAccepted parametersmoveIn
push
revealfromLeft, fromRight, fromBottom, fromTop-pageCurl, pageUnCurlfromLeft, fromRight, fromTop, fromBottomfloat inputColor[];cube
alignedCubefromLeft, fromRight, fromTop, fromBottomfloat inputAmount; (perspective)flip
alignedFlip
oglFlipfromLeft, fromRight, fromTop, fromBottomfloat inputAmount;cameraIris-CGPoint inputPosition;rippleEffect--rotate90cw, 90ccw, 180cw, 180ccw-suckEffect-CGPoint inputPosition;

Availability

The following shows the availability of different CATransitions starting from 2.0

CATransitionAvailabilityfade
moveIn
push
reveal(Public API) 2.0–flip
alignedFlip
oglFlip2.0–cube
alignedCube2.0–pageCurl
pageUnCurl2.0–rippleEffect2.0–suckEffect2.0–cameraIris
cameraIrisHollowOpen
cameraIrisHollowClose2.0–rotate4.0–spewEffect
genieEffect
unGenieEffect
twist
swirl
charminUltra
reflection
zoomyIn
zoomyOut 
mapCurl
mapUnCurl
oglApplicationSuspend
cameraIrisHollow2.0–2.2

References

  • Official reference: CATransition
  • Header: http://github.com/kennytm/iphone-private-frameworks/blob/master/QuartzCore/CATransition2.h

 

UIViewAnimation动画与Core Animation的CATransition类动画

1.使用UIView类函数实现:

//UIViewAnimationTransitionFlipFromLeft, 向左转动
//UIViewAnimationTransitionFlipFromRight, 向右转动
//UIViewAnimationTransitionCurlUp, 向上翻动
//UIViewAnimationTransitionCurlDown, 向下翻动

 

[UIView beginAnimations:@"animationID" context:nil];
[UIView setAnimationDuration:0.5f]; //动画时长
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationTransition: UIViewAnimationTransitionFlipFromLeft forView:self.view cache:YES]; //给视图添加过渡效果
//在这里写你的代码.
[UIView commitAnimations]; //提交动画

 

2.使用CATransition对象来实现:

CATransition比较强大,一般可以使用CATransition模拟UIView的动画。

    /* 过渡效果
fade     //交叉淡化过渡(不支持过渡方向)
push     //新视图把旧视图推出去
moveIn   //新视图移到旧视图上面
reveal   //将旧视图移开,显示下面的新视图
cube     //立方体翻滚效果
oglFlip  //上下左右翻转效果
suckEffect   //收缩效果,如一块布被抽走(不支持过渡方向)
rippleEffect //滴水效果(不支持过渡方向)
pageCurl     //向上翻页效果
pageUnCurl   //向下翻页效果
cameraIrisHollowOpen  //相机镜头打开效果(不支持过渡方向)
cameraIrisHollowClose //相机镜头关上效果(不支持过渡方向)
*/

 

/* 过渡方向
fromRight;
fromLeft;
fromTop;
fromBottom;
*/
CATransition *animation = [CATransition animation];
animation.delegate = self;
animation.duration = 0.5f; //动画时长
animation.timingFunction = UIViewAnimationCurveEaseInOut;
animation.fillMode = kCAFillModeForwards;
animation.type = @”cube”; //过度效果
animation.subtype = @”formLeft”; //过渡方向
animation.startProgress = 0.0 //动画开始起点(在整体动画的百分比)
animation.endProgress = 1.0;  //动画停止终点(在整体动画的百分比)
animation.removedOnCompletion = NO;
[self.view.layer addAnimation:animation forKey:@"animation"];

 

转自:http://www.cnblogs.com/project/archive/2011/09/27/2193556.html

 

实现iPhone漂亮的动画效果主要有两种方法

  一种是UIView层面的,

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

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

  Cpp代码

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

  [UIView setAnimationDuration:0.75];

  [UIView setAnimationDelegate:self];

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

  [myview removeFromSuperview];

  [UIView commitAnimations];

  第二种方式相对复杂一些,但如果更好的进行控制,还是使用这种方法吧,

  基本使用方法可以看一下如下例子:

  Cpp代码

  CATransition *animation = [CATransition animation];

  [animation setDuration:1.25f];

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

  [animation setType:kCATransitionReveal];

  [animation setSubtype: kCATransitionFromBottom];

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

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

  [animation setType:@"suckEffect"];

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

  Cpp代码

  pageCurl 向上翻一页

  pageUnCurl 向下翻一页

  rippleEffect 滴水效果

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

  cube 立方体效果

  oglFlip 上下翻转效果

 

 

 

iphone中CABasicAnimation和UIView动画的区别[转]

关于UIView动画:

  1. [UIView beginAnimations:@"zoom out" context:nil];
  2. [UIView setAnimationDuration:1.f];
  3. [UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
  4. cover.transform = CGAffineTransformMakeScale(9.25,7.05);
  5. cover.center = CGPointMake(430, 512);
  6. [UIView commitAnimations]

UIView动画是应用在一个view上面的。

关于CABasicAnimation动画:

  1. - (CAAnimation *)animationMove:(CGPoint)rootCenter
  2. {
  3.     CABasicAnimation *animationMove
  4.     = [CABasicAnimation animationWithKeyPath:@"position"];
  5.     animationMove.duration = 1;
  6.     animationMove.autoreverses = NO;
  7. //    animationMove.delegate = self;
  8.     animationMove.removedOnCompletion = NO;
  9.     animationMove.fillMode = kCAFillModeForwards;
  10.     animationMove.fromValue = [NSValue valueWithCGPoint:self.oldCoverCenter];
  11.     animationMove.toValue =[NSValue valueWithCGPoint:rootCenter];
  12.  
  13.     return animationMove;
  14. }

CABasicAnimation动画是应用在一个layer上面的。

注:
1,把一个image放在一个view的layer上来放大的时候,如果用UIView来做,图片不会太多的失真和闪烁的效果,但是用CABasicAnimation来做失真和闪烁现象会很严重,效果很不好。
2,做 动画的叠加效果 很简单,只要把各自的动画放在一起就可以了。请看这个效果:一本书边移动到屏幕中间,边放大,边打开封面的效果。

  1. [imageLayer addAnimation:[self animationOpen] forKey:@"Open"];
  2. [UIView beginAnimations:@"zoom out" context:nil];
  3. [UIView setAnimationDuration:1.f];
  4. [UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
  5. cover.transform = CGAffineTransformMakeScale(5.5,5.5);
  6. cover.center = CGPointMake(629, 384);
  7. [UIView commitAnimations];
  8.  
  9. - (CAAnimation *)animationOpen
  10. {
  11.     CABasicAnimation *animationOpen
  12.     = [CABasicAnimation animationWithKeyPath:@"transform.rotation.y"];
  13.     animationOpen.duration = 1;
  14.     animationOpen.autoreverses = NO;
  15.     animationOpen.delegate = self;  //然后执行真正地打开书的内容
  16.     animationOpen.removedOnCompletion = NO;
  17.     animationOpen.fillMode = kCAFillModeForwards;
  18.     animationOpen.fromValue = [NSNumber numberWithFloat:-M_PI/5];
  19.     animationOpen.toValue = [NSNumber numberWithFloat:-M_PI/1.5];
  20.  
  21.     return animationOpen;
  22. }
0 0
原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 椰汁拧不开瓶盖怎么办 装蜂蜜的玻璃罐打不开怎么办 蚂蚱没有草吃了怎么办 笔记本电源已接通未充电怎么办 电源已接通未充电怎么办 遮盖纹身好了颜色淡了怎么办 致炫方向盘变重怎么办 xp音频图标没了怎么办 狙击精英3没子弹怎么办 干活干的手腕疼怎么办 干了活不给钱怎么办 干了活要不到钱怎么办 活干完了钱不给怎么办 微信语音聊天音量很小怎么办 一手软件崩溃钱卡住了怎么办 身上皮肤很黑怎么办?好想穿短裙 家里有很多小飞虫怎么办 家里有垃圾中飞出虫子怎么办 雷蛇笔记本很烫怎么办 登录监控器的账号锁了怎么办 悦借钱登录账号被锁怎么办 365账号登录被锁怎么办 台式电脑cpu温度过高怎么办 UG2.0打不开错误—15怎么办 键盘空格键删除键失灵怎么办 耳麦检测声音不分左右怎么办 吃生萝卜胃疼怎么办 幼兔拉稀怎么办没精神 自酿米酒酸了怎么办 用冰敷脸感觉红烫了怎么办 吃了海兔的内脏怎么办 吃了鱿鱼的吸盘怎么办 想开个烧烤店没学过怎么办 墨鱼汁弄衣服上怎么办 干鱿鱼泡开发黄怎么办 吃了芥末胃疼怎么办 手撕鱿鱼咸了怎么办 孕妇吃了点芥末怎么办 葡萄酒上面有一层白霉怎么办 手机一不小心把视频删了怎么办 柑橘7月份果实小怎么办