zoukankan      html  css  js  c++  java
  • ios 动画效果CATransition笔记

       初学ios开发,很多概念还不清楚,所以只有边学边做例子。又怕学了后面忘了前面,因此用自己的博客来纪录自己的学习历程,也是对自己学习不要懈怠做个监督。

        刚学ios做动画效果。因为ios封装得很好,实现ios的漂亮动画效果也很简单,却因为我自己的粗心落了一个字母 导致纠结了一天,这个教训必须记住,同时也懂得了调试技能在编程里地位也是非常重要的存在。

       实现ios动画有两种方法:一种UIView层面的,一种是使用CATransition.

    1. - (void)viewDidLoad  
    2. {  
    3.     [super viewDidLoad];  
    4.     // Do any additional setup after loading the view.  
    5.       
    6.     UIView *redView = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] bounds]];  
    7.     redView.backgroundColor = [UIColor redColor];  
    8.     [self.view addSubview:redView];  
    9.       
    10.     UIView *yellowView = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] bounds]];  
    11.     yellowView.backgroundColor = [UIColor yellowColor];  
    12.     [self.view addSubview:yellowView];  
    13.       
    14.     UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];  
    15.     [button setTitle:@"改变1" forState:UIControlStateNormal];  
    16.     button.frame = CGRectMake(10, 10, 300, 40);  
    17.     [button addTarget:self action:@selector(changeUIView1) forControlEvents:UIControlEventTouchUpInside];  
    18.     [self.view addSubview:button];  
    19.       
    20.   
    21.       
    22.     UIButton *button2 = [UIButton buttonWithType:UIButtonTypeRoundedRect];  
    23.     [button2 setTitle:@"改变2" forState:UIControlStateNormal];  
    24.     button2.frame = CGRectMake(10, 120, 300, 40);  
    25.     [button2 addTarget:self action:@selector(changeUIView2) forControlEvents:UIControlEventTouchUpInside];  
    26.     [self.view addSubview:button2];  
    27. }  
    28. -(void) changeUIView1{  
    29.     [UIView beginAnimations:@"animation" context:nil];  
    30.     [UIView setAnimationDuration:1.0f];  
    31.     [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];  
    32.     [UIView setAnimationTransition:UIViewAnimationTransitionCurlDown forView:self.view cache:YES];  
    33.     [self.view exchangeSubviewAtIndex:1 withSubviewAtIndex:0  ];  
    34.     [UIView commitAnimations];  
    35. }  
    36.   
    37. -(void) changeUIView2{  
    38.    CATransition *transition = [CATransition animation];  
    39.     transition.delegate = self;  
    40.     transition.duration = 2.0f;  
    41.     transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn];  
    42.     transition.type = kCATransitionPush;  
    43.     transition.type = @"pageCurl"  ;//另一种设置动画效果方法  
    44.     transition.subtype = kCATransitionFromBottom;  
    45.     [self.view exchangeSubviewAtIndex:1 withSubviewAtIndex:0];  
    46.     [self.view.layer addAnimation:transition forKey:@"animation"];  
    47. }  


    调用CATransition需要在frameworks中添加QuartzCore.framework,在.h文件中加入  #import <QuartzCore/QuartzCore.h>

    setType:有四种类型:

        

        kCATransitionFade                   //交叉淡化过渡

        kCATransitionMoveIn               //移动覆盖原图

        kCATransitionPush                    //新视图将旧视图推出去

        kCATransitionReveal                //底部显出来

    另一种设置方法

       pageCurl     //向上翻一页

        pageUnCurl   //向下翻一页

        rippleEffect   //滴水效果

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

        cube       //立方体效果

        oglFlip      //上下翻转效果


    setSubtype:有四种类型:

        

        kCATransitionFromRight

        kCATransitionFromLeft(默认值)

        kCATransitionFromTop

        kCATransitionFromBottom

  • 相关阅读:
    session
    Cookie
    HttpServletRequest
    HttpServletResponse response(中文乱码、文件下载、定时刷新、控制缓存、重定向、注意事项)
    采购价格
    SAP 会计凭证
    STO 后台配置
    SAP 公司间采购
    SAP Dependency 相关性
    SAP 委外加工
  • 原文地址:https://www.cnblogs.com/A--G/p/4711682.html
Copyright © 2011-2022 走看看