zoukankan      html  css  js  c++  java
  • IOS动画(5)转场动画

    看舞台剧时当需要更改舞台背景时,舞台大幕会缓缓合上,然后缓缓打开,舞台上的内容就变了。

    转场动画的意义就类似于舞台大幕,当layer上的内容变化时,我们希望通过一种动画的效果来切换,CoreAnimation提供了CATransition实现转场效果。

    - (void)viewDidLoad
    {
        [super viewDidLoad];
    
        UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(20, 20, 120, 120)];
        imageView.image = [UIImage imageNamed:@"5.png"];
        [self.view addSubview:imageView];
        
        UIImageView *imageView2 = [[UIImageView alloc] initWithFrame:CGRectMake(20, 20, 120, 120)];
        imageView2.image = [UIImage imageNamed:@"4.png"];
        [self.view addSubview:imageView2];
    }
    
    
    
    - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
        CATransition *transition = [CATransition animation];
        transition.type = kCATransitionMoveIn;
        transition.subtype = kCATransitionFromLeft;
      
     transition.duration = 1;
        [self.view.layer addAnimation:transition forKey:nil];
        [self.view exchangeSubviewAtIndex:2 withSubviewAtIndex:3];
    
    }

     CATransition中又两个关键参数需要设置:type和subtype,前者控制转场动画的类型,后者控制转场动画的方向

    type支持以下取值

    kCATransitionFade  渐隐效果

    kCATransitionMoveIn  移入效果

    kCATransitionPush  推入效果

    kCATransitionReveal  揭开效果

    除了上面四种值,type还支持以下的私有动画

    cube  立方体旋转

    suckEffect  被吸入效果

    oglFlip  翻转

    rippleEffect  水波动画

    pageCurl  页面揭开

    pageUnCurl  页面放下

    cameraIrisHollowOpen  镜头打开

    cameraIrisHollowClose  镜头关闭

     

    subtype提供四个动画方向,支持以下取值

    kCATransitionFromRight

    kCATransitionFromLeft

    kCATransitionFromTop

    kCATransitionFromBottom

     

    此外,也可以通过UIView的beginAnimation:context:和commitAnimation实现转场动画

    - (void)viewDidLoad
    {
        [super viewDidLoad];
    
        UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(20, 20, 120, 120)];
        imageView.image = [UIImage imageNamed:@"5.png"];
        [self.view addSubview:imageView];
        
        UIImageView *imageView2 = [[UIImageView alloc] initWithFrame:CGRectMake(20, 20, 120, 120)];
        imageView2.image = [UIImage imageNamed:@"4.png"];
        [self.view addSubview:imageView2];
    }
    
    
    
    - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
     
        [UIView beginAnimations:nil context:nil];
        [UIView setAnimationDuration:0.5];
        [UIView setAnimationTransition:UIViewAnimationTransitionCurlDown forView:self.view cache:YES];
        [UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
        [self.view exchangeSubviewAtIndex:2 withSubviewAtIndex:3];
        [UIView commitAnimations];
    }

    setAniamtionTransition支持以下属性

    UIViewAnimationTransitionNone  无动画

    UIViewAnimationTransitionFlipFromLeft  从左边滑入

    UIViewAnimationTransitionFlipFromRight  从右边滑入

    UIViewAnimationTransitionCurlUp  翻开书页

    UIViewAnimationTransitionCurlDown  放下书页

     

    setAniamtionCurve支持以下属性

    UIViewAnimationCurveEaseInOut         // slow at beginning and end

    UIViewAnimationCurveEaseIn            // slow at beginning

    UIViewAnimationCurveEaseOut           // slow at end

    UIViewAnimationCurveLinear

  • 相关阅读:
    转载ORACLE批量绑定FORALL与BULK COLLECT
    Oracle Locking Survival Guide
    转载:TOAD中查看执行计划
    Oracle 9i/10g编程艺术笔记第七章 并发与多版本
    C#调用Oracle存储过程返回多结果集
    转载oracle 字符集查看与修改
    转载:Oracle的优化器(Optimizer)
    Oracle 随笔
    转载:Oracle中SQL语句执行效率的查找与解决
    当查询和设置需要输入Pn时界面的处理方法
  • 原文地址:https://www.cnblogs.com/zanglitao/p/4047978.html
Copyright © 2011-2022 走看看