欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  移动技术

详解IOS图层转场动画

程序员文章站 2023-01-01 18:25:38
caanimation的子类,用于做转场动画,能够为层提供移出屏幕和移入屏幕的动画效果。ios比mac os x的转场动画效果少一点 uinavigationcontro...

caanimation的子类,用于做转场动画,能够为层提供移出屏幕和移入屏幕的动画效果。ios比mac os x的转场动画效果少一点
uinavigationcontroller就是通过catransition实现了将控制器的视图推入屏幕的动画效果
属性解析:

  • type:动画过渡类型
  • subtype:动画过渡方向
  • startprogress:动画起点(在整体动画的百分比)
  • endprogress:动画终点(在整体动画的百分比)

具体代码:

/* 过渡效果
 fade   //交叉淡化过渡(不支持过渡方向) kcatransitionfade
 push   //新视图把旧视图推出去 kcatransitionpush
 movein  //新视图移到旧视图上面  kcatransitionmovein
 reveal  //将旧视图移开,显示下面的新视图 kcatransitionreveal
 cube   //立方体翻滚效果
 oglflip //上下左右翻转效果
 suckeffect  //收缩效果,如一块布被抽走(不支持过渡方向)
 rippleeffect //滴水效果(不支持过渡方向)
 pagecurl   //向上翻页效果
 pageuncurl  //向下翻页效果
 camerairishollowopen //相机镜头打开效果(不支持过渡方向)
 camerairishollowclose //相机镜头关上效果(不支持过渡方向)
*/
  
/* 过渡方向
 kcatransitionfromright
 kcatransitionfromleft
 kcatransitionfrombottom



//转场动画--》是针对某个view的图层进行转场动画
#import "viewcontroller.h"
#import <quartzcore/quartzcore.h>

@interface viewcontroller ()
{
  uiview *_lastview;
  bool flag;
}
@end

@implementation viewcontroller

- (void)viewdidload
{
  [super viewdidload];
  flag=true;
  uiview *view=[[uiview alloc] initwithframe:cgrectmake(100, 100, 200, 200)];
  view.backgroundcolor=[uicolor redcolor];
  [self.view addsubview:view];
  [view release];
  _lastview=view;
  // do any additional setup after loading the view, typically from a nib.
}

-(void)touchesbegan:(nsset *)touches withevent:(uievent *)event{
  if(flag){
    _lastview.backgroundcolor=[uicolor yellowcolor];
    flag=false;
  
  }
  else{
    _lastview.backgroundcolor=[uicolor redcolor];
    flag=true;
  }
  
  //转场动画--就是对某个view进行动画切换。
  //1:如果是控制器之间的切换,其实window上view进行切换
  catransition *transion=[catransition animation];
  //设置转场动画的类型
  transion.type=@"pagecurl";
  //设置转场动画的方向
  transion.subtype=@"fromleft";
  
  //把动画添加到某个view的图层上
  [self.view.layer addanimation:transion forkey:nil];
  
}

 控制器直接切换动画

 uiapplication *app=[uiapplication sharedapplication];
  appdelegate *dd=app.delegate;
  
    myviewcontroller *my=[[myviewcontroller alloc] init];
  //切换根控制器,其实把视图控制器的view在window上切换。所以在转场动画要作用在window上
  dd.window.rootviewcontroller=my;
  catransition *trans=[catransition animation];
  
  trans.type=@"pagecurl";
  trans.subtype=@"fromtop";
  
  [dd.window.layer addanimation:trans forkey:nil];
  
  [my release];

以上就是本文的全部内容,希望对大家的学习有所帮助。