先上效果图:

这篇文章完全是为造轮子制作:原作者是码农界的吴彦祖

作者视频下载地址

好的,我梳理一下思路:

理清思路

||转场动画可以理解为一个对象,在这个对象里封装了一个动画.具体的我们跟着代码走

!.实现协议的方法

在一个继承NSObject的类中遵守协议实现代理

 #import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
@interface PushTranstion : NSObject<UIViewControllerAnimatedTransitioning>
@property (nonatomic,strong)id transitationContext;
@end

在这里遵守一个协议,声明一个属性变量全局操作

方法实现

//  PushTranstion.m
// 专场动画
//
// Created by MAc on 16/5/27.
// Copyright © 2016年 MAc. All rights reserved.
// #import "PushTranstion.h" @implementation PushTranstion
//转场动画实现的时间 这里设置的长便于观察
- (NSTimeInterval)transitionDuration:(id<UIViewControllerContextTransitioning>)transitionContext{
return 4.0;
}
//设置动画效果
- (void)animateTransition:(id<UIViewControllerContextTransitioning>)transitionContext {
_transitationContext=transitionContext;
UIViewController *fromViewController = [transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey];
UIViewController * toViewController = [transitionContext viewControllerForKey:UITransitionContextToViewControllerKey];
UIView * containerView = [transitionContext containerView];
[containerView addSubview:fromViewController.view];
[containerView addSubview:toViewController.view]; /* 创建一个矩阵The identity transform: [1 0 0 0; 0 1 0 0; 0 0 1 0; 0 0 0 1]. */ CATransform3D transform = CATransform3DIdentity;
//设置影射效果,是转场显得更真实
transform.m34 = - 1/1500.0;
toViewController.view.layer.transform =transform;
//设置锚点:(边长为1,锚点指的是(0.5,0.5))
toViewController.view.layer.anchorPoint = CGPointMake(1.0, 0.5); //设置锚点之后,试图左移动了0.5个View.With,重写设置position(锚点在俯视图中的位置,)
/* The position in the superlayer that the anchor point of the layer's
* bounds rect is aligned to. Defaults to the zero point. Animatable. */
toViewController.view.layer.position= CGPointMake(CGRectGetMaxX(fromViewController.view.frame), CGRectGetMidY(fromViewController.view.frame));
CABasicAnimation * animation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.y"];
animation.duration = [self transitionDuration:transitionContext];
//从pi/2开始旋转
animation.fromValue = @(M_PI_2);
animation.toValue=@(0);
animation.delegate =self;
[toViewController.view.layer addAnimation:animation forKey:@"rotateAnimation"]; }
//动画结束的时候通知上下文
- (void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag{
if (flag) {
//[_transitationContext finishInteractiveTransition];
[_transitationContext completeTransition:YES];
}
}
@end

转场对象设定好了,下面就去vc中实现转场动画

在这之前,要理解一件事.转场动画的两个界面是放在一个容器里面的,即前面提到的containerView中放着的两个view,一个fromView 一个toView

其实就是toView旋转铺在fromView上的操作 ,接着看vc中的代码

//
// ViewController.m
// 专场动画
//
// Created by MAc on 16/5/27.
// Copyright © 2016年 MAc. All rights reserved.
// #import "ViewController.h"
#include "PushTranstion.h"
//#import "PushTransitionTest.h"
@interface ViewController ()<UINavigationControllerDelegate>{
//和手势搭配使用,单独使用会报不知名错
UIPercentDrivenInteractiveTransition * interaction;
} @end @implementation ViewController
- (IBAction)push:(id)sender {
// interaction = [[UIPercentDrivenInteractiveTransition alloc] init];
[self performSegueWithIdentifier:@"PushToS" sender:nil];
} - (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib. }
-(void)viewDidAppear:(BOOL)animated{
[super viewDidAppear:YES];
self.navigationController.delegate = self;
} - (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
self.navigationController.delegate = nil;
} - (nullable id <UIViewControllerAnimatedTransitioning>)navigationController:(UINavigationController *)navigationController
animationControllerForOperation:(UINavigationControllerOperation)operation
fromViewController:(UIViewController *)fromVC
toViewController:(UIViewController *)toVC
{
if (operation == UINavigationControllerOperationPush) {
return [[PushTranstion alloc] init];
}
return nil;
} @end

这样,这个转场动画的效果就实现了,后面还有对吴彦祖的视频的分析讲解,不清楚的地方相互交流,欢迎留言!

转场动画1-Push 动画的更多相关文章

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

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

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

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

  3. 关于push动画中尺寸问题

    由于是在sb中写的VC, 所以在跳转动画时, 就会有一些问题. 这是sb中的约束: 当在push动画时, 在中间界面添加imageView时, 如图: imageView的尺寸是如上图所示, 并不是屏 ...

  4. iOS 自定义Tabbar实现push动画隐藏效果

    http://wonderffee.github.io/blog/2013/08/07/hide-custom-tab-bar-with-animation-when-push/ 在之前的一篇文章(链 ...

  5. 【Flutter 实战】动画序列、共享动画、路由动画

    老孟导读:此篇文章是 Flutter 动画系列文章第四篇,本文介绍动画序列.共享动画.路由动画. 动画序列 Flutter中组合动画使用Interval,Interval继承自Curve,用法如下: ...

  6. iOS开发UI篇—核心动画(UIView封装动画)

    iOS开发UI篇—核心动画(UIView封装动画) 一.UIView动画(首尾) 1.简单说明 UIKit直接将动画集成到UIView类中,当内部的一些属性发生改变时,UIView将为这些改变提供动画 ...

  7. 核心动画基础动画(CABasicAnimation)关键帧动画

    1.在iOS中核心动画分为几类: 基础动画(CABasicAnimation) 关键帧动画(CAKeyframeAnimation) 动画组(CAAnimationGroup) 转场动画(CATran ...

  8. 核心动画(UIView封装动画)

    一.UIView动画(首尾) 1.简单说明 UIKit直接将动画集成到UIView类中,当内部的一些属性发生改变时,UIView将为这些改变提供动画支持 执行动画所需要的工作由UIView类自动完成, ...

  9. Objective-C 使用核心动画CAAnimation实现动画

    先来看看效果吧 整个核心动画就不多做介绍了,随便一搜就能有很多很详细的解释,主要使用以下四种 CABasicAnimation //经典动画 CAKeyframeAnimation //关键帧动画 C ...

  10. Core Animation 动画的使用:关键帧动画、基础动画、动画组

    首先让我们了解下什么是 Core Animation,Core Animation 为核心动画,他为图形渲染和动画提供了基础.使用核心动画,我们只需要设置起点.终点.关键帧等一些参数,剩下的工作核心动 ...

随机推荐

  1. Python学习笔记6-Python中re(正则表达式)模块学习

    今天学习了Python中有关正则表达式的知识.关于正则表达式的语法,不作过多解释,网上有许多学习的资料.这里主要介绍Python中常用的正则表达式处理函数. re.match re.match 尝试从 ...

  2. AndroidUI 布局动画-为布局添加动画

    除了可以为视图添加动画以外,还可以为视图的布局添加动画: <RelativeLayout xmlns:android="http://schemas.android.com/apk/r ...

  3. Apache的Access.log分析总结

    Apache的Access.log分析总结 #查看80端口的tcp连接  #netstat -tan | grep "ESTABLISHED" | grep ":80&q ...

  4. 确定比赛名次(map+邻接表 邻接表 拓扑结构 队列+邻接表)

    确定比赛名次 Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other) Total Submis ...

  5. javaEE servlet获取jsp内置对象

    既然jsp和servlet是等价的,在jsp中能够使用内置对象,那么在servlet中也能够使用. 1.获得out对象 能够使用例如以下代码获得out对象: import java.io.PrintW ...

  6. andengine游戏引擎总结进阶篇1

    本篇包括虚拟键盘,粒子系统 1虚拟键盘 分为两种,一种是单个虚拟键盘,另一种是多个方位虚拟键盘 1)加载虚拟键盘所需要的图片资源 private BitmapTextureAtlas mOnScree ...

  7. Java RMI 学习笔记

    概况 功能:提供了客户辅助对象和服务辅助对象,为客户辅助对象创建和服务辅助对象形同的方法. 优点:客户不必写任何网络或I/O代码,调用远程方法就和运行在客户自己的本地JVM上对对象进行的正常方法一样. ...

  8. HTTP头信息(转)--1

    转自:http://www.cnblogs.com/9988/archive/2012/03/21/2409086.html 我用抓包软件抓了http的包,发现accept大多数有两种情况. 第一种: ...

  9. QF——iOS通知中心(NotificationCener)

    前面我们讲iOS不同界面间传值的时候,说过可以通过通知中心进行传值.那到底什么是通知中心,他是如何实现传值的呢? NSNotificationCenter是单例的,只提供了一个唯一的实例化入口,在整个 ...

  10. 终于解决“Git Windows客户端保存用户名与密码”的问题

    这就是正确答案,我们已经验证过了,下面详细描述一下解决方法: 1. 在Windows中添加一个HOME环境变量,值为%USERPROFILE%,如下图: 2. 在“开始>运行”中打开%Home% ...