• iOS图层转场动画


      1 动画类型
      2 
      3 
      4 CAAnimation的子类,用于做转场动画,能够为层提供移出屏幕和移入屏幕的动画效果。iOS比Mac OS X的转场动画效果少一点
      5 UINavigationController就是通过CATransition实现了将控制器的视图推入屏幕的动画效果
      6 属性解析:
      7 type:动画过渡类型
      8 subtype:动画过渡方向
      9 startProgress:动画起点(在整体动画的百分比)
     10 endProgress:动画终点(在整体动画的百分比)
     11 
     12 
     13  
     14 
     15 
     16 /* 过渡效果
     17 
     18  fade     //交叉淡化过渡(不支持过渡方向) kCATransitionFade
     19 
     20  push     //新视图把旧视图推出去  kCATransitionPush
     21 
     22  moveIn   //新视图移到旧视图上面   kCATransitionMoveIn
     23 
     24  reveal   //将旧视图移开,显示下面的新视图  kCATransitionReveal
     25 
     26  cube     //立方体翻滚效果
     27 
     28  oglFlip  //上下左右翻转效果
     29 
     30  suckEffect   //收缩效果,如一块布被抽走(不支持过渡方向)
     31 
     32  rippleEffect //滴水效果(不支持过渡方向)
     33 
     34  pageCurl     //向上翻页效果
     35 
     36  pageUnCurl   //向下翻页效果
     37 
     38  cameraIrisHollowOpen  //相机镜头打开效果(不支持过渡方向)
     39 
     40  cameraIrisHollowClose //相机镜头关上效果(不支持过渡方向)
     41 
     42 */
     43 
     44    
     45 
     46 /* 过渡方向
     47 
     48  kCATransitionFromRight
     49 
     50  kCATransitionFromLeft
     51 
     52  kCATransitionFromBottom
     53 
     54 
     55 
     56 
     57 
     58 
     59 
     60 
     61 
     62 
     63 //转场动画--》是针对某个view的图层进行转场动画
     64 #import "ViewController.h"
     65 #import <QuartzCore/QuartzCore.h>
     66 
     67 @interface ViewController ()
     68 {
     69     UIView *_lastview;
     70     BOOL flag;
     71 }
     72 @end
     73 
     74 @implementation ViewController
     75 
     76 - (void)viewDidLoad
     77 {
     78     [super viewDidLoad];
     79     flag=true;
     80     UIView *view=[[UIView alloc] initWithFrame:CGRectMake(100, 100, 200, 200)];
     81     view.backgroundColor=[UIColor redColor];
     82     [self.view addSubview:view];
     83     [view release];
     84     _lastview=view;
     85     // Do any additional setup after loading the view, typically from a nib.
     86 }
     87 
     88 -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
     89     if(flag){
     90         _lastview.backgroundColor=[UIColor yellowColor];
     91         flag=false;
     92     
     93     }
     94     else{
     95         _lastview.backgroundColor=[UIColor redColor];
     96         flag=true;
     97     }
     98     
     99     //转场动画--就是对某个view进行动画切换。
    100     //1:如果是控制器之间的切换,其实window上view进行切换
    101     CATransition *transion=[CATransition animation];
    102     //设置转场动画的类型
    103     transion.type=@"pageCurl";
    104     //设置转场动画的方向
    105     transion.subtype=@"fromLeft";
    106     
    107     //把动画添加到某个view的图层上
    108     [self.view.layer addAnimation:transion forKey:nil];
    109     
    110 }

    控制器转场

     1 UIApplication *app=[UIApplication sharedApplication];
     2     AppDelegate *dd=app.delegate;
     3     
     4         MyViewController *my=[[MyViewController alloc] init];
     5     //切换根控制器,其实把视图控制器的view在window上切换。所以在转场动画要作用在window上
     6     dd.window.rootViewController=my;
     7     CATransition *trans=[CATransition animation];
     8    
     9     trans.type=@"pageCurl";
    10     trans.subtype=@"fromTop";
    11    
    12     [dd.window.layer addAnimation:trans forKey:nil];
    13     
    14     [my release];
  • 相关阅读:
    Powerdesigner数据库建模--概念模型--ER图【转】
    oralce闪回
    DBA
    linux socket使用经验总结
    寒假学习笔记1:结构化程序设计
    寒假作业2:简化电梯设计elevator
    鹤发银丝映日月,丹心热血沃新花——忆三位良师
    走廊泼水节
    种树
    P2938 [USACO09FEB]股票市场Stock Market
  • 原文地址:https://www.cnblogs.com/Fc-ios/p/3791880.html
Copyright © 2020-2023  润新知