iOS 页面之间的转场动画控制器间的转换

时间:2023-08-25 15:05:02

CATransition类实现层的转场动画。你可以从一组预定义的转换或者通过提供定制的CIFilter实例来指定转场效果。

例如:控制器之间的跳转

LoginViewController *myVC = [[LoginViewController alloc]init];

myVC.tuichu = @"tuichu";

//创建动画

CATransition *animation = [CATransition animation];

//设置运动轨迹的速度

animation.timingFunction = UIViewAnimationCurveEaseInOut;

//设置动画类型为立方体动画

animation.type = @"cube";

//设置动画时长

animation.duration =0.5f;

//设置运动的方向

animation.subtype =kCATransitionFromRight;

//控制器间跳转动画

[[UIApplication sharedApplication].keyWindow.layer addAnimation:animation forKey:nil];

[self presentViewController:myVC animated:NO completion:nil];

//例如;控制器中添加 view

CATransition *animation = [CATransition animation];

animation.timingFunction = UIViewAnimationCurveEaseInOut;

animation.type = @"rippleEffect"; //声波效果

animation.duration = 0.3;

animation.subtype = kCATransitionFromBottom;

[self.view.layer addAnimation:animation forKey:nil];

[self.view addSubview:view];

  //定义个转场动画

  CATransition *animation = [CATransition animation];

  //转场动画持续时间

  animation.duration = 0.2f;

  //计时函数,从头到尾的流畅度???

  animation.timingFunction=UIViewAnimationCurveEaseInOut;

  //转场动画类型

  animation.type = kCATransitionReveal;

  //转场动画将去的方向

  animation.subtype = kCATransitionFromBottom;

  //动画时你需要的实现

  self.tabBarController.tabBar.hidden = YES;

  //添加动画 (转场动画是添加在层上的动画)

  self.tabBarController.tabBar.layer addAnimation:animation forKey:@"animation"];

  说明:

  duration:动画持续的时长。

  timingFunction:没明白(谁明白的说明一下吧)

  type:转场动画的类型。如果在一个自定义的转场动画中指定的过滤器属性,此属性将被忽略。

  type共有四种类型:

  NSString * const kCATransitionFade;//逐渐消失

  NSString * const kCATransitionMoveIn;//移入

  NSString * const kCATransitionPush;//平移(暂且这么称呼吧)

  NSString * const kCATransitionReveal;//显露

  默认类型为kCATransitionFade。

  subtype:转场动画将要去往的方向。

  subtpye有四种类型:

  NSString * const kCATransitionFromRight;

  NSString * const kCATransitionFromLeft;

  NSString * const kCATransitionFromTop;

  NSString * const kCATransitionFromBottom;

  默认方向是nil。

  [self.tabBarController.tabBar.layer addAnimation:animation forKey:@"animation"];

  转场动画是添加给layer的!

  switch (btn.tag) {

  case 0:

  animation.type = @"cube";//---立方体

  break;

  case 1:

  animation.type = @"suckEffect";//103 吸走的效果

  break;

  case 2://前后翻转效果

  animation.type = @"oglFlip";//When subType is "fromLeft" or "fromRight", it's the official one.

  break;

  case 3:

  animation.type = @"rippleEffect";//110波纹效果

  break;

  case 4:

  animation.type = @"pageCurl";//101翻页起来

  break;

  case 5:

  animation.type = @"pageUnCurl";//102翻页下来

  break;

  case 6:

  animation.type = @"cameraIrisHollowOpen ";//107//镜头开

  break;

  case 7:

  animation.type = @"cameraIrisHollowClose ";//106镜头关

  break;

  default:

  break;

  }