iphone 动画总结

最普通动画:

//开始动画

[UIView beginAnimations:nil context:nil];  

//设定动画持续时间

[UIView setAnimationDuration:2];

//动画的内容

frame.origin.x += 150;

[img setFrame:frame];

//动画结束

[UIView commitAnimations];

 

连续动画:一个接一个地显示一系列的图像

NSArray *myImages = [NSArray arrayWithObjects: 

[UIImage imageNamed:@"myImage1.png"], 

[UIImage imageNamed:@"myImage2.png"], 

[UIImage imageNamed:@"myImage3.png"], 

[UIImage imageNamed:@"myImage4.gif"], nil];

 

UIImageView *myAnimatedView = [UIImageView alloc]; 

[myAnimatedView initWithFrame:[self bounds]]; 

myAnimatedView.animationImages = myImages; //animationImages属性返回一个存放动画图片的数组

myAnimatedView.animationDuration = 0.25; //浏览整个图片一次所用的时间

myAnimatedView.animationRepeatCount = 0; // 0 = loops forever 动画重复次数

[myAnimatedView startAnimating]; 

[self addSubview:myAnimatedView]; 

[myAnimatedView release]; 

 

CATransition Public API动画:

CATransition *animation = [CATransition animation];

//动画时间

    animation.duration = 0.5f;

//先慢后快

    animation.timingFunction = UIViewAnimationCurveEaseInOut;

 animation.fillMode = kCAFillModeForwards;

 //animation.removedOnCompletion = NO;

 

//各种动画效果

 /*

kCATransitionFade;

kCATransitionMoveIn;

kCATransitionPush;z

kCATransitionReveal;

*/

 /*

kCATransitionFromRight;

kCATransitionFromLeft;

kCATransitionFromTop;

kCATransitionFromBottom;

*/

//各种组合

animation.type = kCATransitionPush;

animation.subtype = kCATransitionFromRight; 

 

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

 

CATransition Private API动画:

animation.type可以设定为以下效果

动画效果汇总:

/*

 suckEffect(三角)

 

 rippleEffect(水波抖动)

 

 pageCurl(上翻页)

 

 pageUnCurl(下翻页)

 

 oglFlip(上下翻转)

 

 cameraIris/cameraIrisHollowOpen/cameraIrisHollowClose  (镜头快门,这一组动画是有效果,只是很难看,不建议使用

 

 而以下为则黑名单:

 

 spewEffect: 新版面在屏幕下方中间位置被释放出来覆盖旧版面.

 

 - genieEffect: 旧版面在屏幕左下方或右下方被吸走, 显示出下面的新版面 (阿拉丁灯神?).

 

 - unGenieEffect: 新版面在屏幕左下方或右下方被释放出来覆盖旧版面.

 

 - twist: 版面以水平方向像龙卷风式转出来.

 

 - tubey: 版面垂直附有弹性的转出来.

 

 - swirl: 旧版面360度旋转并淡出, 显示出新版面.

 

 - charminUltra: 旧版面淡出并显示新版面.

 

 - zoomyIn: 新版面由小放大走到前面, 旧版面放大由前面消失.

 

 - zoomyOut: 新版面屏幕外面缩放出现, 旧版面缩小消失.

 

 - oglApplicationSuspend: 像按"home" 按钮的效果.

 */

 

UIView Animations 动画:

[UIView beginAnimations:@"animationID" context:nil];

[UIView setAnimationDuration:0.5f];

[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];

[UIView setAnimationRepeatAutoreverses:NO];

//以下四种效果

/*

[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:self.view cache:YES];//oglFlip, fromLeft 

[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:self.view cache:YES];//oglFlip, fromRight  

[UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:self.view cache:YES];

[UIView setAnimationTransition:UIViewAnimationTransitionCurlDown forView:self.view cache:YES];

*/

 

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

[UIView commitAnimations];

IOS4.0新方法:

方法: +(void)animateWithDuration:(NSTimeInterval)duration animations:(void (^)(void))animations;

+ (void)animateWithDuration:(NSTimeInterval)duration animations:(void (^)(void))animations completion:(void (^)(BOOL finished))completion; //多一个动画结束后可以执行的操作.

//下边是嵌套使用,先变大再消失的动画效果.

[UIView animateWithDuration:1.25 animations:^{

 CGAffineTransform newTransform = CGAffineTransformMakeScale(1.2, 1.2);

[firstImageView setTransform:newTransform];

[secondImageView setTransform:newTransform];} 

completion:^(BOOL finished){

[UIView animateWithDuration:1.2 animations:^{

[firstImageView setAlpha:0];

[secondImageView setAlpha:0];} completion:^(BOOL finished){ 

[firstImageView removeFromSuperview]; 

[secondImageView removeFromSuperview]; }]; 

}];

UIView的各种动态效果Demo(10/03/04小更新)   

进一步修改,现在应该接近完整了。







引用
受这贴启发 http://www.cocoachina.com/bbs/read.php?tid-11856.html
做了一点更新


引用
技术主管的侄子接到一个任务,要求实现UIView切换时的动态效果。居然这个任务签了很多钱,估计有上千欧……
我很无语,我说这个就几句话来着……
我们技术主管是负责Mac代码的,对iPhone编程不太了解。我做了个Demo给她,顺便放上了咱CocoaChina的logo,嘿嘿
[ 此帖被bobgreen在2010-03-04 09:28重新编辑 ]
图片:Screen shot 2010-03-03 at 18.06.01 .png 
图片:1.png 
图片:2.png 
图片:3.png 

地图程序那样的Curl效果分享   

看了很多例子的CurlUp和CurlDown,都是翻页效果,没有像地图那样翻到一半停下的,偶然在网上看到了方法,自己做了一个例子,不敢独享,拿出来大家看一下。
关键代码如下:
复制代码
  1. - (IBAction)curlUp{
  2.     NSLog(@"Curl");
  3.     // Curl the image up or down
  4.     CATransition *animation = [CATransition animation];
  5.     [animation setDelegate:self];
  6.     [animation setDuration:0.35];
  7.     [animation setTimingFunction:UIViewAnimationCurveEaseInOut];
  8.     if (!curled){
  9.         animation.type = @"pageCurl";
  10.         animation.fillMode = kCAFillModeForwards;
  11.         animation.endProgress = 0.58;
  12.     } else {
  13.         animation.type = @"pageUnCurl";
  14.         animation.fillMode = kCAFillModeBackwards;
  15.         animation.startProgress = 0.42;
  16.     }
  17.     [animation setRemovedOnCompletion:NO];
  18.     [view exchangeSubviewAtIndex:0 withSubviewAtIndex:1];
  19.     
  20.     [view addAnimation:animation forKey:@"pageCurlAnimation"];
  21.     
  22.     // Disable user interaction where necessary
  23.     if (!curled) {
  24.         
  25.     } else {
  26.         
  27.     }
  28.     
  29.     curled = !curled;
  30. }
[ 此帖被gagaga在2009-12-07 17:18重新编辑 ]
图片:屏幕快照 2009-12-07 下午04.24.18.png 
实现pushViewController的自定义动画效果
厌烦了千篇一律的push风格了吗 ? 试试这个吧

CATransition *transition = [CATransition animation];
transition .duration = 1.0f;
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
transition.type = @"cube";
transition.subtype = kCATransitionFromRight;
transition.delegate = self;
[self.navigationController.view.layer addAnimation:transition forKey:nil];


DemoViewController *demoViewController = 
[[ DemoViewController  alloc]
initWithNibName:@" DemoViewController "
bundle:[NSBundle mainBundle]];
[self.navigationController pushViewController: demoViewController animated:YES]; 


[demoViewController release];


简单介绍:.type  设置了主要的页面切换显示形式 cube 等
 .subtype 设置了页面的旋转  左右上下 :~)

附件:    MapCurlEffect.zip (17 K) 下载次数:1408

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值