动画效果汇总(一):页面跳转和添加

我的博客大部分都是从笔记直接拉过来的,没有精雕细琢,请见谅。这一篇最后一段代码还是有点用的。

1.   基本动画

 
 
  1. //动画
  2.    [UIView beginAnimations:nil context:nil];
  3.    //设定动画持续时间
  4.    [UIView setAnimationDuration:2];
  5.    //动画的内容
  6.    frame.origin.y += 150;
  7.    [imageView setFrame:frame];
  8.    //动画结束
  9.    [UIView commitAnimations];

2.动画切换页面 

地址:http://blog.163.com/wzi_xiang/blog/static/65982961201211193275578/

由VIewController跳转到VIewController

代码:

   

 
 
  1. //自定义动画
  2.    CATransition *transition = [CATransition animation];
  3.    transition.duration = 2.0f;
  4.    //动画时间控制
  5.    transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
  6.    //是否代理
  7.    transition.delegate = self;
  8.    //是否在当前层完成动画
  9.    transition.removedOnCompletion = NO;
  10.  
  11.    //设置动画效果:这两个参数是关键
  12.    transition.type = @"cameraIrisHollowOpen";
  13.    transition.subtype = kCATransitionMoveIn;
  14.  
  15.    AnimationViewController *animationController = [[AnimationViewController alloc]init];
  16. //注意此处设置为NO
  17.    [UIView beginAnimations:nil context:nil];
  18.    [UIView setAnimationDuration:2.0];
  19.    [UIView setAnimationDelegate:self];//是否需要实现协议
  20. //    [UIView setAnimationDidStopSelector:@selector(pushAnimationDidStop)];
  21. //    [UIView setAnimationTransition:transition forView:self.view cache:YES];
  22. //    [UIView commitAnimations];
  23.  
  24.    [self.navigationController pushViewController:animationController animated:NO];
  25.    [self.navigationController.view.layer addAnimation:transition forKey:nil];

3.添加View时的动画(参见程序AnimationTest2)

 
 
  1. //关键语句
  2. [view.layer addAnimation:animation forKey:@"animation”];

4.Transition关键词

对应的type有一下类型(共计16种):

animation.type =

kCATransitionFade;

kCATransitionPush;

kCATransitionReveal;

kCATransitionMoveIn;

@“cube";

@“suckEffect";

@“oglFlip";

@“rippleEffect";

@“pageCurl";

@“pageUnCurl";

@“cameraIrisHollowOpen";

@“cameraIrisHollowClose";

//这四种使用方法和以上12种不一样(见第5点)

UIViewAnimationTransitionCurlDown;

UIViewAnimationTransitionCurlUp;

UIViewAnimationTransitionFlipFromLeft;

UIViewAnimationTransitionFlipFromRight;


对应的subtype有四种:(对应4个方向)

kCATransitionFromLeft;

kCATransitionFromBottom;

kCATransitionFromRight;

kCATransitionFromTop;


5. #pragma UIView实现动画

 
 
  1. - (void)animationWithView:(UIView *)view WithAnimationTransition:(UIViewAnimationTransition)transition
  2. {
  3.    [UIView animateWithDuration:2.0f animations:^{
  4.        [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
  5.        [UIView setAnimationTransition:transition forView:view cache:YES];
  6.    }];
  7. }

6.可调用动画方法

  
  
  1. #pragma CATransiton动画实现
  2. - (void)transitionWithType:(NSString *)type WithSubtype:(NSString *)subtype
  3.                   ForView:(UIView *)view
  4. {
  5.    //创建CATransition对象
  6.    CATransition *animation = [CATransition animation];
  7.    animation.duration = 2.0;
  8.  
  9.    animation.subtype =
  10.    //设置运动type
  11.    animation.type = type;
  12.    if (subtype != nil)
  13.    {
  14.        //设置子类
  15.        animation.subtype = subtype;
  16.    }
  17.  
  18.    //设置运动速度
  19.    animation.timingFunction = UIViewAnimationOptionCurveEaseInOut;
  20.  
  21.    [view.layer addAnimation:animation forKey:@"animation"];
  22. }

7.从ViewController跳转到另一个

所有视图控制器继承BaseController:

  
  
  1. //BaseController.h
  2. typedef enum
  3. {
  4.    Transition_left = 5678,//从左侧滑出,返回
  5.    Transition_right,//从右侧滑出,push
  6.    Transition_reveal,//揭开效果
  7.    Transition_moveIn,//覆盖效果
  8.    Transition_cube,//立方体效果
  9.    Transition_suckEffect,//吮吸效果
  10.    Transition_oglFlip,//翻转效果
  11.    Transition_RippleEffect,//波纹
  12.    Transition_pageCurl,//翻页
  13.    Transition_pageUnCurl,//反翻页
  14.    Transition_cameraOpen,//开镜头
  15.    Transition_cameraClose,//关镜头
  16.    Transition_curlDown,//下翻页效果
  17.    Transition_curlUp,//上翻页效果
  18.    Transition_flipLeft,//左翻转效果
  19.    Transition_flipRight,//右翻转效果
  20. }TransitionEffect;
  21. @interface BaseController : UIViewController
  22. /**
  23. *  跳转到某个继承本类的ViewController:如果该类已经存在,则pop回去;如果不存在则push
  24. *
  25. *  @param vc     要跳转的页面
  26. *  @param effect 跳转效果:可以指定向左跳转,向右跳转及其他效果
  27. */
  28. - (void)pushToVc:(UIViewController *)vc withTransition:(TransitionEffect)effect;
  29. @end
   
   
  1. //BaseController.h
  2. - (void)pushToVc:(BaseController *)vc withTransition:(TransitionEffect)effect
  3. {
  4.    for (UIViewController *viewController in self.navigationController.viewControllers)
  5.    {
  6.        if ([viewController isKindOfClass:[vc class]])
  7.        {
  8.            [self gotoViewController:viewController withTransition:effect isPush:NO];
  9.            return;
  10.        }
  11.    }
  12.    [self gotoViewController:vc withTransition:effect isPush:YES];
  13. }
  14. - (void)gotoViewController:(UIViewController *)vc withTransition:(TransitionEffect)effect isPush:(BOOL)ispush
  15. {
  16.    switch (effect)
  17.    {
  18.        case Transition_left:
  19.            [self transitionWithType:kCATransitionPush WithSubtype:kCATransitionFromLeft ForView:self.navigationController.view];
  20.            break;
  21.        case Transition_right:
  22.            [self transitionWithType:kCATransitionPush WithSubtype:kCATransitionFromRight ForView:self.navigationController.view];
  23.            break;
  24.        case Transition_reveal:
  25.            [self transitionWithType:kCATransitionReveal WithSubtype:kCATransitionFromLeft ForView:self.navigationController.view];
  26.            break;
  27.        case Transition_moveIn:
  28.            [self transitionWithType:kCATransitionMoveIn WithSubtype:kCATransitionFromLeft ForView:self.navigationController.view];
  29.            break;
  30.        case Transition_cube:
  31.            [self transitionWithType:@"cube" WithSubtype:kCATransitionFromLeft ForView:self.navigationController.view];
  32.            break;
  33.        case Transition_suckEffect:
  34.            [self transitionWithType:@"suckEffect" WithSubtype:kCATransitionFromLeft ForView:self.navigationController.view];
  35.            break;
  36.        case Transition_oglFlip:
  37.            [self transitionWithType:@"oglFlip" WithSubtype:kCATransitionFromLeft ForView:self.navigationController.view];
  38.            break;
  39.        case Transition_RippleEffect:
  40.            [self transitionWithType:@"rippleEffect" WithSubtype:kCATransitionFromLeft ForView:self.navigationController.view];
  41.            break;
  42.        case Transition_pageCurl:
  43.            [self transitionWithType:@"pageCurl" WithSubtype:kCATransitionFromLeft ForView:self.navigationController.view];
  44.            break;
  45.        case Transition_pageUnCurl:
  46.            [self transitionWithType:@"pageUnCurl" WithSubtype:kCATransitionFromLeft ForView:self.navigationController.view];
  47.            break;
  48.        case Transition_cameraOpen:
  49.            [self transitionWithType:@"cameraIrisHollowOpen" WithSubtype:kCATransitionFromLeft ForView:self.navigationController.view];
  50.            break;
  51.        case Transition_cameraClose:
  52.            [self transitionWithType:@"cameraIrisHollowClose" WithSubtype:kCATransitionFromLeft ForView:self.navigationController.view];
  53.            break;
  54.        case Transition_curlDown:
  55.            [self animationWithView:self.navigationController.view WithAnimationTransition:UIViewAnimationTransitionCurlDown];
  56.            break;
  57.        case Transition_curlUp:
  58.            [self animationWithView:self.navigationController.view WithAnimationTransition:UIViewAnimationTransitionCurlUp];
  59.            break;
  60.        case Transition_flipLeft:
  61.            [self animationWithView:self.navigationController.view WithAnimationTransition:UIViewAnimationTransitionFlipFromLeft];
  62.            break;
  63.        case Transition_flipRight:
  64.            [self animationWithView:self.navigationController.view WithAnimationTransition:UIViewAnimationTransitionFlipFromRight];
  65.            break;
  66.        default:
  67.            break;
  68.    }
  69.    if (ispush)
  70.    {
  71.        [self.navigationController pushViewController:vc animated:NO];
  72.    }
  73.    else
  74.    {
  75.        [self.navigationController popToViewController:vc animated:NO];
  76.    }
  77. }
  78. #pragma CATransiton动画实现
  79. - (void)transitionWithType:(NSString *)type WithSubtype:(NSString *)subtype
  80.                   ForView:(UIView *)view
  81. {
  82.    //创建CATransition对象
  83.    CATransition *animation = [CATransition animation];
  84.    animation.duration = 0.5;
  85.    //设置运动type
  86.    animation.type = type;
  87.    if (subtype != nil)
  88.    {
  89.        //设置子类
  90.        animation.subtype = subtype;
  91.    }
  92.    
  93.    //设置运动速度
  94.    animation.timingFunction = UIViewAnimationOptionCurveEaseInOut;
  95.    
  96.    [view.layer addAnimation:animation forKey:@"animation"];
  97. }
  98. #pragma UIView实现动画
  99. - (void)animationWithView:(UIView *)view WithAnimationTransition:(UIViewAnimationTransition)transition
  100. {
  101.    [UIView animateWithDuration:0.5 animations:^{
  102.        [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
  103.        [UIView setAnimationTransition:transition forView:view cache:YES];
  104.    }];
  105.    
  106. }

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值