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

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

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

)

代码直接上

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

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

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

demo地址

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

最新文章

  1. Python Set Literals
  2. Coretext实现图文混排及Gif图片播放
  3. 使用cocoapods导入第三方类库后 头文件没有代码提示?
  4. MD5 加密的两种方法
  5. Codeigniter 利用加密Key(密钥)的对象注入漏洞
  6. asp.net获取当前页面源码并生成静态页面
  7. COJ 0358 xjr考考你数据结构(根号3)线段树区间修改
  8. CSU 1119 Collecting Coins
  9. CentOS安装glibc-2.14,错误安装libc.so.6丢失急救办法
  10. shell 整理,更新,记录
  11. 深入理解java虚拟机之——JVM垃圾回收策略总结
  12. P1040 加分二叉树
  13. 盗版SQL Server的性能限制
  14. sql 多条记录插入
  15. mongodb中比较级查询条件:($lt $lte $gt $gte)(大于、小于)、查找条件
  16. Java面向对象——类,对象和方法
  17. 我的代码-date
  18. java学习-- equals和hashCode的关系
  19. 机器Coding For WinForm
  20. centos 安装arcgis server 10.1

热门文章

  1. EasyList China国内镜像
  2. win下vm10+mac os 10.9安装遇到问题
  3. 固定cell.imageView.image的大小
  4. MySQL报错:ERROR 1045 (28000): Access denied for user &#39;root&#39;@&#39;localhost&#39; (using password:NO)
  5. 《Oracle Applications DBA 基础》- 9 - Concurrent Processing[Z]
  6. json(转)
  7. js arguments参数说明
  8. Python核心编程读笔 5: python的序列
  9. JS输出当前时间,且每秒变化
  10. HTML知识点摘记