`
janedoneway
  • 浏览: 568070 次
  • 性别: Icon_minigender_1
  • 来自: 广州
社区版块
存档分类
最新评论

浅析IOS视图切换动画效果

 
阅读更多

From: http://mmz06.blog.163.com/blog/static/12141696201151925118682/

 

引入

简要说明IOS中动画的实现……

说明

为了避免视图之间切换呆板问题,在IPHONE中引入了转换动画效果,分别在UIKit.frameworkQuartzCore.framework之中。总的来说两者的播放方向都是left,right,up(top),down(bottom)四种,只不过后者的动画类型要比前者丰富一些。

  好了,现在来看看代码中是怎样实现动画效果的(注意看颜色标注的区别):

CODE:

/*

 * @DO 视图切换动画

 * @param sender(id)

 */

- (void) switchViews:(id)sender

{

// 准备动画

// [UIView beginAnimations:@"Curl"context:nil];

// 动画播放持续时间

// [UIView setAnimationDuration:1.25];

// 动画速度

// [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];

 

// 准备动画

CATransition *animation = [CATransition animation];

//动画播放持续时间

[animation setDuration:0.25f];

//动画速度,何时快、慢

[animation setTimingFunction:[CAMediaTimingFunction

                          functionWithName:kCAMediaTimingFunctionEaseIn]];

if (self.showViewController.view.superview == nil)

    {

    //  动画方向

    //  [UIView setAnimationTransition: UIViewAnimationTransitionCurlUp

    //       forView:self.view cache:YES];

    /*动画效果

     (

       kCATransitionFade淡出|

       kCATransitionMoveIn覆盖原图|

       kCATransitionPush推出|

       kCATransitionReveal底部显出来

     )

     */

    [animation setType:kCATransitionReveal];

    /*动画方向

     (

       kCATransitionFromRight|

       kCATransitionFromLeft|

       kCATransitionFromTop|

       kCATransitionFromBottom

     )

   */

    [animation setSubtype:kCATransitionFromBottom];

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

        [saveViewController.view removeFromSuperview];

        [self.view insertSubview:showViewController.viewatIndex:0];

    }

    else

    {

    //  动画方向

    //  [UIView setAnimationTransition: UIViewAnimationTransitionCurlDown

    //     forView:self.view  cache:YES];

    /*动画效果

     (

       suckEffect三角|

       rippleEffect水波|

       pageCurl上翻页|

       pageUnCurl下翻页|

       oglFlip上下翻转|  

     )

     */

    [animation setType:@"suckEffect"];

    //开始动画

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

        [showViewController.view removeFromSuperview];

    [self.view insertSubview:saveViewController.view atIndex:0];

    }

// 结束动画

// [UIView commitAnimations];

}

 

    其中suckEffect三角 rippleEffect水波 pageCurl上翻页 pageUnCurl下翻页 oglFlip上下翻转这五类动画很少用,主要有两点:1、后者还没有经过官方的发布,很多资料都没有去介绍;2、考虑到其随时都会被官方更改,为着程序的稳定性等因素不去采用。    最后提下,UIKIT.frame中的动画是对UIView的而后者是针对视图的属性layer来实现的,后者与视图动画比起来,具备更大的优势,更容易进行转换,倾斜,放大,缩小等等。

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics