一般我们就用两种转场push和present

present

/**
1.设置代理
- (instancetype)init
{
self = [super init];
if (self) {
self.transitioningDelegate = self;
self.modalPresentationStyle = UIModalPresentationCustom;
}
return self;
}
2.添加协议<UIViewControllerTransitioningDelegate>
3.重写协议方法 - 在协议方法里面初始化
- (id<UIViewControllerAnimatedTransitioning>)animationControllerForPresentedController:(UIViewController *)presented presentingController:(UIViewController *)presenting sourceController:(UIViewController *)source{ } - (id<UIViewControllerAnimatedTransitioning>)animationControllerForDismissedController:(UIViewController *)dismissed{ }
**/

2.push

第一个控制器推第二个控制器的时候

   ViewController2 *vc = [[ViewController2 alloc]init];
self.navigationController.delegate = vc; //必须写这句话
[self.navigationController pushViewController:vc animated:YES];

第二个控制器

@interface ViewController2 : UIViewController<UINavigationControllerDelegate>

@end

代理方法

- (id<UIViewControllerAnimatedTransitioning>)navigationController:(UINavigationController *)navigationController animationControllerForOperation:(UINavigationControllerOperation)operation fromViewController:(UIViewController *)fromVC toViewController:(UIViewController *)toVC {

}

上面就是push和present发生的地方,都需要返回一个 UIViewControllerAnimatedTransitioning

所以我们写一个类

@interface WJTransiation_Mobile : NSObject<UIViewControllerAnimatedTransitioning>

@end

然后修改里面的协议方法

//动画时间

- (NSTimeInterval)transitionDuration:(nullable id <UIViewControllerContextTransitioning>)transitionContext;

//自定义过渡动画

- (void)animateTransition:(id <UIViewControllerContextTransitioning>)transitionContext;

执行过渡动画

1.获取前后控制器

   UIViewController *toVC = [transitionContext viewControllerForKey:UITransitionContextToViewControllerKey];
UIViewController *fromVC = [transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey];

2.获得转场动画视图

UIView *containerView = [transitionContext containerView];

3.将前后控制器需要进行动画的视图添加到containerView上

   [containerView addSubview:tempView];
[containerView addSubview:toVC.view];

4.执行自己的动画

demo链接:http://pan.baidu.com/s/1kTPPUMb

效果图:

补:

//动态添加transiationView属性

@interface UIViewController (transiationView)

@property (nonatomic,strong)UIView *transiationView;

@end
#import <objc/runtime.h>

@implementation UIViewController (transiationView)

static char transiationViewKey;

- (void)setTransiationView:(UIView *)transiationView {
return objc_setAssociatedObject(self, &transiationViewKey, transiationView, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
} - (UIView *)transiationView {
return objc_getAssociatedObject(self, &transiationViewKey);
} @end

iOS转场动画初探的更多相关文章

  1. iOS 转场动画探究(一)

    什么是转场动画: 转场动画说的直接点就是你常见的界面跳转的时候看到的动画效果,我们比较常见的就是控制器之间的Push和Pop,还有Present和Dismiss的时候设置一下系统给我们的modalTr ...

  2. iOS 转场动画探究(二)

    这篇文章是接着第一篇写的,要是有同行刚看到的话建议从前面第一篇看,这是第一篇的地址:iOS 转场动画探究(一) 接着上一篇写的内容: 上一篇iOS 转场动画探究(一)我们说到了转场要素的第四点,把那个 ...

  3. iOS转场动画

    文顶顶 最怕你一生碌碌无为 还安慰自己平凡可贵 iOS开发UI篇—核心动画(转场动画和组动画) iOS开发UI篇—核心动画(转场动画和组动画) 一.转场动画简单介绍 CAAnimation的子类,用于 ...

  4. iOS转场动画封装

    写在前面 iOS在modal 或push等操作时有默认的转场动画,但有时候我们又需要特定的转场动画效果,从iOS7开始,苹果就提供了自定义转场的API,模态推送present和dismiss.导航控制 ...

  5. iOS - 转场动画

    苹果在 iOS7 定制了 ViewController 的切换效果 一 在iOS5和iOS6之前,ViewController的切换主要有4种 Push/Pop,NavigationViewCotnr ...

  6. iOS 转场动画核心内容

    CATransition——转场动画 CATransition是CAAnimation的子类,用于做转场动画,能够为层提供移出屏幕和移入屏幕的动画效果.iOS比Mac OS X的转场动画效果少一点. ...

  7. IOS 转场动画二和透明控制器视图

    一.透明视图控制器 WJListMenuViewController *VC = [[WJListMenuViewController alloc]init]; VC.modalPresentatio ...

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

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

  9. iOS 开发--转场动画

    "用过格瓦拉电影,或者其他app可能都知道,一种点击按钮用放大效果实现转场的动画现在很流行,效果大致如下:" 本文主讲SWIFT版,OC版在后面会留下Demo下载 在iOS中,在同 ...

随机推荐

  1. uvm_test——测试用例的起点

    在UVM平台验证中,所有的test cases都extends uvm_test,首先,来看源代码 //------------------------------------------------ ...

  2. django连接Oracle过程中出现的问题

    开始时版本信息: python 3.6   +   ce_oracle 6 最终版本信息: python 3.5   + ce_oracle 5.2 ce_oracle版本问题 cx_Oracle-5 ...

  3. Javascript根据指定下标或对象删除数组元素

    删除数组元素在工作中经常会用到,本文讲解一下Javascript根据下标删除数组元素的方法,需要了解的朋友可以参考下 将一下代码放在全局js文件中: Js代码 /** *删除数组指定下标或指定对象 * ...

  4. OracleDBConsole启动不了

    今天要用OEM,然后去打开OracleDBConsoleXXX, 提示说什么么么2,然后就各种百度...最后发现...有断了网络连接之后就可以把它启动了...简直惨,不知道这是什么原理,还有Oracl ...

  5. js中声明函数的三种方式

    己亥年  庚午月 癸巳日  宜入宅 忌婚嫁 函数声明方式 声明 : function first(){}: 调用:first() 函数表达式声明方式   声明: var second=function ...

  6. 第三届上海市大学生网络安全大赛wp&学习

    wp 0x00 p200 先分析了程序关键的数据结构 分析程序逻辑,在free堆块的时候没有清空指针,造成悬挂指针,并且程序中给了system('/bin/sh'),可以利用uaf 脚本如下: 1.先 ...

  7. fckeditor的实例

                            第一步:去官网下载,删除多余的包 删除所有”_”开头的文件和文件夹   删除FCKeditor的目录下:   fckeditor.afp fckedit ...

  8. ext笔记

    命名   The top-level namespaces and the actual class names should be CamelCased. Everything else shoul ...

  9. windows10锁定屏幕聚焦图片导出

    打开运行,输入%LocalAppData%\Packages\Microsoft.Windows.ContentDeliveryManager_cw5n1h2txyewy\LocalState\Ass ...

  10. springboot 修炼之路

    网上无意中发现一份关于springboot的教程说明,说的很详细,大家可以参考.具体地址:http://www.spring4all.com/article/246