转场动画2-Pop动画
上一篇试讲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地址
下一篇解析 吴彦祖的手势,尽请期待
转场动画2-Pop动画的更多相关文章
- iOS动画——弹窗动画(pop动画)
用pop动画简单实现弹窗的缩放和渐变,感觉这个动画常用,就写一下博客 pop动画是Facebook推出的动画引擎,请自行到GitHub上搜索下载拖拽导入xcode项目中. 更多pop动画使用和原理可网 ...
- POP动画[1]
POP动画[1] pop动画是facebook扩展CoreAnimation的,使用及其方便:) 1:Spring系列的弹簧效果(两个动画kPOPLayerBounds与kPOPLayerCorner ...
- POP动画[3]
POP动画[3] 这一节主要讲解POP动画的自定义动画属性. POP动画中有一个参数,叫timingFunction,与CoreAnimation中的一个参数CAMediaTimingFunction ...
- POP动画[2]
POP动画[2] 1:定制控制器间的转场动画. 源码有点多-_-!! // // RootViewController.h // Animation // // Copyright (c) 2014年 ...
- iOS开发UI篇—核心动画(转场动画和组动画)
转自:http://www.cnblogs.com/wendingding/p/3801454.html iOS开发UI篇—核心动画(转场动画和组动画) 一.转场动画简单介绍 CAAnimation的 ...
- 用POP动画引擎实现衰减动画(POPDecayAnimation)
效果图: #import "ViewController.h" #import <POP.h> @interface ViewController () @end @i ...
- POP动画引擎中Layer与CALayer的一点区别
POP动画引擎是facebook提供的一个开源框架, 可以实现很多的动画效果, 这里就不一一介绍啦, 有兴趣的童鞋请移步: https://github.com/facebook/pop 下面简单的讲 ...
- 用POP动画编写带富文本的自定义动画效果
用POP动画编写带富文本的自定义动画效果 [源码] https://github.com/YouXianMing/UI-Component-Collection [效果] [特点] * 支持富文本 * ...
- 用POP动画模拟真实秒钟摆动效果
用POP动画模拟真实秒钟摆动效果 静态图: 动画图: 此处用到了POP中的Spring系列动画,现提供源码如下: SecondClockView.h 与 SecondClockView.m // // ...
- ios基础动画、关键帧动画、动画组、转场动画等
概览 在iOS中随处都可以看到绚丽的动画效果,实现这些动画的过程并不复杂,今天将带大家一窥iOS动画全貌.在这里你可以看到iOS中如何使用图层精简非交互式绘图,如何通过核心动画创建基础动画.关键帧动画 ...
随机推荐
- HDOJ 2689
Sort it Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Su ...
- UpdatePanel局部刷新用法
AjaxTest.aspx代码: <%@ Page Language="C#" AutoEventWireup="true" CodeBehind=&qu ...
- Sql Server 服务器名称\实例名称 无法连接 Server Name\Instance Name
解决步骤: 1: Sql Server是否已经启动. 2: 检查Sql Server服务器是否开启TCP/IP协议. 侦听的默认端口为1433 3: ping 数据库 ...
- 发布前,Bat Script备份服务器的Website
由于远程访问服务器,操作滞后验证,备份不方便.我试了两种方式,VBScript和利用7zip的脚本自动备份网站.下面有简单的说明供参考. 1. VBScript, 使用VB脚本打包,不稳定,在服务器上 ...
- ResultSet与Result
微软的.NET平台上面的数据访问有一个特点,就是数据查询的结果,可以放在内存中,以XML格式进行描述,不需要一直与数据库保持在线连接,用DataSet + Data Adapter来实现! 而在JDB ...
- C# 创建数组的几种方法
第一种 string[] myArray=new string[10]; 第二种 string[] myArray={"1","2"}; 第三种 string[ ...
- EC读书笔记系列之10:条款16、17
条款18 让接口容易被正确使用,不易被误用 记住: ★“促进正确使用”的办法包括接口的一致性,以及与内置类型的行为兼容 ★“阻止误用”的办法包括建立新类型.限制类型上的操作,束缚对象值,以及消除客户的 ...
- 《CSAPP》读书杂记 - Chapter 2. Representing and Manipulating Information
1. 一段查看地址内容的代码 代码: #include <stdio.h> typedef unsigned char *byte_pointer; void show_bytes(byt ...
- mysql集群安装配置
看网上很多人说mysql集群不是很稳定,因此这2天做了下mysql的集群,打算配置没有什么问题了,过2天做下相关的性能测试,我的配置环境如下: 操作系统: Centos5.2 软件 ...
- iOS定位与地图
定位: 手机上定位的实现主要有三种方式:基站(附近基站的位置),wifi(所连接路由器的位置),卫星(最准确,也最耗能). iOS的定位功能主要是由CLLocationManager类来完成的.这个类 ...