上一篇试讲push动画,这篇分解pop动画

里面关于矩阵有不懂得,参考CATransform3D 特效详解

上图(虚拟机下,图是渣渣

)

代码直接上

  1. //
  2. // PopTransition.h
  3. // 转场动画2-Pop
  4. //
  5. // Created by MAc on 16/5/28.
  6. // Copyright © 2016年 李赵杰. All rights reserved.
  7. //
  8. #import <Foundation/Foundation.h>
  9. #import <UIKit/UIKit.h>
  10. @interface PopTransition : NSObject<UIViewControllerAnimatedTransitioning>
  11. /** 全局上下文 */
  12. @property (nonatomic,strong) id transitionContext;
  13. /** fromViewController */
  14. @property (nonatomic,strong) UIViewController * fromViewController;
  15. @end

实现方法和Push里面基本一致

  1. //
  2. // PopTransition.m
  3. // 转场动画2-Pop
  4. //
  5. // Created by MAc on 16/5/28.
  6. // Copyright © 2016年 李赵杰. All rights reserved.
  7. //
  8. #import "PopTransition.h"
  9. @implementation PopTransition
  10. - (NSTimeInterval)transitionDuration:(id<UIViewControllerContextTransitioning>)transitionContext{
  11. return 5.0;
  12. }
  13. - (void)animateTransition:(id <UIViewControllerContextTransitioning>)transitionContext{
  14. _transitionContext = transitionContext;
  15. UIViewController * fromViewController = [transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey];
  16. UIViewController * toViewController = [transitionContext viewControllerForKey:UITransitionContextToViewControllerKey];
  17. UIView * containerView = [transitionContext containerView];
  18. _fromViewController = fromViewController;
  19. [containerView addSubview:toViewController.view];
  20. [containerView addSubview:fromViewController.view];
  21. CATransform3D transform =CATransform3DIdentity;
  22. //这个值表示: m34(透视效果,要操作的这个对象要有旋转的角度,否则没有效果。正直/负值都有意义)
  23. transform.m34 = - 1/1500.0;
  24. fromViewController.view.layer.transform = transform;
  25. fromViewController.view.layer.anchorPoint = CGPointMake(1, 0.5);
  26. fromViewController.view.layer.position =CGPointMake(CGRectGetMaxX(toViewController.view.frame),CGRectGetMidY(toViewController.view.frame));
  27. CABasicAnimation * animation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.y"];
  28. animation.duration = [self transitionDuration:transitionContext];
  29. animation.fromValue = @(0);
  30. animation.toValue =@(M_PI_2);
  31. animation.delegate = self;
  32. [fromViewController.view.layer addAnimation:animation forKey:@"rotateAnimation"];
  33. }
  34. -(void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag{
  35. if (flag) {
  36. // This must be called whenever a transition completes (or is cancelled.)
  37. // Typically this is called by the object conforming to the
  38. // UIViewControllerAnimatedTransitioning protocol that was vended by the transitioning
  39. // delegate. For purely interactive transitions it should be called by the
  40. // interaction controller. This method effectively updates internal view
  41. // controller state at the end of the transition.
  42. //意思就是:必须调用在转场动画结束时(取消),.... 最后这个方法有效的更新了试图控制器中转场动画的状态
  43. [_transitionContext completeTransition:YES];
  44. }
  45. }
  46. @end
  1. //
  2. // PopViewController.m
  3. // 转场动画2-Pop
  4. //
  5. // Created by MAc on 16/5/28.
  6. // Copyright © 2016年 李赵杰. All rights reserved.
  7. //
  8. #import "PopViewController.h"
  9. #import "PopTransition.h"
  10. @interface PopViewController ()<UINavigationControllerDelegate>
  11. @end
  12. @implementation PopViewController
  13. - (void)viewDidAppear:(BOOL)animated{
  14. [super viewDidAppear:animated];
  15. self.navigationController.delegate = self;
  16. }
  17. -(void)viewDidDisappear:(BOOL)animated{
  18. [super viewDidDisappear:animated];
  19. self.navigationController.delegate =nil;
  20. }
  21. - (void)viewDidLoad {
  22. [super viewDidLoad];
  23. // Do any additional setup after loading the view.
  24. }
  25. - (id<UIViewControllerAnimatedTransitioning>)navigationController:(UINavigationController *)navigationController animationControllerForOperation:(UINavigationControllerOperation)operation fromViewController:(UIViewController *)fromVC toViewController:(UIViewController *)toVC{
  26. if (operation == UINavigationControllerOperationPop) {
  27. return [[PopTransition alloc]init];
  28. }
  29. return nil;
  30. }
  31. - (void)didReceiveMemoryWarning {
  32. [super didReceiveMemoryWarning];
  33. // Dispose of any resources that can be recreated.
  34. }
  35. /*
  36. #pragma mark - Navigation
  37. // In a storyboard-based application, you will often want to do a little preparation before navigation
  38. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  39. // Get the new view controller using [segue destinationViewController].
  40. // Pass the selected object to the new view controller.
  41. }
  42. */
  43. @end

demo地址

下一篇解析 吴彦祖的手势,尽请期待

转场动画2-Pop动画的更多相关文章

  1. iOS动画——弹窗动画(pop动画)

    用pop动画简单实现弹窗的缩放和渐变,感觉这个动画常用,就写一下博客 pop动画是Facebook推出的动画引擎,请自行到GitHub上搜索下载拖拽导入xcode项目中. 更多pop动画使用和原理可网 ...

  2. POP动画[1]

    POP动画[1] pop动画是facebook扩展CoreAnimation的,使用及其方便:) 1:Spring系列的弹簧效果(两个动画kPOPLayerBounds与kPOPLayerCorner ...

  3. POP动画[3]

    POP动画[3] 这一节主要讲解POP动画的自定义动画属性. POP动画中有一个参数,叫timingFunction,与CoreAnimation中的一个参数CAMediaTimingFunction ...

  4. POP动画[2]

    POP动画[2] 1:定制控制器间的转场动画. 源码有点多-_-!! // // RootViewController.h // Animation // // Copyright (c) 2014年 ...

  5. iOS开发UI篇—核心动画(转场动画和组动画)

    转自:http://www.cnblogs.com/wendingding/p/3801454.html iOS开发UI篇—核心动画(转场动画和组动画) 一.转场动画简单介绍 CAAnimation的 ...

  6. 用POP动画引擎实现衰减动画(POPDecayAnimation)

    效果图: #import "ViewController.h" #import <POP.h> @interface ViewController () @end @i ...

  7. POP动画引擎中Layer与CALayer的一点区别

    POP动画引擎是facebook提供的一个开源框架, 可以实现很多的动画效果, 这里就不一一介绍啦, 有兴趣的童鞋请移步: https://github.com/facebook/pop 下面简单的讲 ...

  8. 用POP动画编写带富文本的自定义动画效果

    用POP动画编写带富文本的自定义动画效果 [源码] https://github.com/YouXianMing/UI-Component-Collection [效果] [特点] * 支持富文本 * ...

  9. 用POP动画模拟真实秒钟摆动效果

    用POP动画模拟真实秒钟摆动效果 静态图: 动画图: 此处用到了POP中的Spring系列动画,现提供源码如下: SecondClockView.h 与 SecondClockView.m // // ...

  10. ios基础动画、关键帧动画、动画组、转场动画等

    概览 在iOS中随处都可以看到绚丽的动画效果,实现这些动画的过程并不复杂,今天将带大家一窥iOS动画全貌.在这里你可以看到iOS中如何使用图层精简非交互式绘图,如何通过核心动画创建基础动画.关键帧动画 ...

随机推荐

  1. Error occured processing XML &#39;Cannot find class [springmvc.extention.BeanArgumentResolver]&#39;.

    <Description Resource Path Location Type Error occured processing XML 'Cannot find class [springm ...

  2. java中文乱码解决之道(二)—–字符编码详解:基础知识 + ASCII + GB**

    原文出处:http://cmsblogs.com/?p=1412 在上篇博文(java中文乱码解决之道(一)—–认识字符集)中,LZ简单介绍了主流的字符编码,对各种编码都是点到为止,以下LZ将详细阐述 ...

  3. 使用Vitamio打造自己的Android万能播放器(4)——本地播放(快捷搜索、数据存储)

    前言 关键字:Vitamio.VPlayer.Android播放器.Android影音.Android开源播放器 本章节把Android万能播放器本地播放的主要功能(缓存播放列表和A-Z快速查询功能) ...

  4. Ibatis代码自动生成工具——Abator安装与应用实例(图解)

    Abator 能自动生成DAO,DTO和sqlMap,大大提高开发效率.Abator 的官方网站:http://ibatis.apache.org/ibator.html 使用也比较简单,以下做个实例 ...

  5. ASP.NET递归添加树节点

    表设计如图: id        title         parentid 1         asp.net   0 2         c#           0 3         c#_ ...

  6. Nodejs随笔(一):Hello World!

    声明:本人用的是Ubuntu 14.04 LTS 系统. 一.Nodejs安装: <1>直接apt-get安装,最简单:sudo apt-get install nodejs <2& ...

  7. SVN报错:can't open file db/txn-current-lock:permission denied 解决方法

    其实这个问题是这样的.下面我举个例子:比如版本库SVN是root用户创建的但是启动服务的时候没有选择root启动,而是在其他用户转托管太下启动的,所以只能读不能写. 解决方法:停止svn服务:kill ...

  8. SEL数据类型,@selector的用法,以及调用SEL

    1.SEL数据类型 SEL是个指针类型的数据,类似C语言中的函数指针.在OC中,每个对象方法都有其对应着一个SEL变量.当我们调用对象方法时,编译器会将该方法转换成一个SEL的数据,然后去类中寻找该方 ...

  9. Rectangles

    Given two rectangles and the coordinates of two points on the diagonals of each rectangle,you have t ...

  10. Android 如何让 app 自行处理 power key M

    前言          欢迎大家我分享和推荐好用的代码段~~ 声明          欢迎转载,但请保留文章原始出处:          CSDN:http://www.csdn.net        ...