一般我们就用两种转场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. 项目在cocos 2.23移植到cocos 3.1.0所出现的bug

    在建项目时一定要注意选择源代码!而不是预编译库 "extensions/ExtensionMacros.h”: No such file 项目右键-属性-配置属性-c/c++ - 常规-附加 ...

  2. [windows]解决Win7访问Windows 2003、XP共享慢的问题

    解决方法: 1. 修改网卡配置打开本地连接属性,点击"配置"在"高级"选项卡中,将"大型发送分载(IPv4)"的值设置成"禁用&q ...

  3. No input file specified的解决方法

    (一)IIS Noinput file specified 方法一:改PHP.ini中的doc_root行,打开ini文件注释掉此行,然后重启IIS 方法二:请修改php.ini找到; cgi.for ...

  4. Azure 项目构建 - 构建 WordPress 网站

    本课程主要介绍了如何基于 Azure Web 应用和 WordPress 快速构建网站,实践讲解如何使用 Azure Web 应用,创建并连接 MySQL Database on Azure, 使用 ...

  5. Nginx性能优化参考

    nginx性能优化参考 1)调整配置文件中的配置项的值(配置文件:nginx.conf) worker_processes auto;开启的进程数,一般配置为跟逻辑CPU核数一样worker_rlim ...

  6. java.lang.NoClassDefFoundError: org/w3c/dom/ElementTraversal问题解决

    使用Maven构建项目并加载spring配置文件时,报如下异常 Caused by: java.lang.ClassNotFoundException: org.w3c.dom.ElementTrav ...

  7. leetcode_1049. Last Stone Weight II_[DP]

    1049. Last Stone Weight II https://leetcode.com/problems/last-stone-weight-ii/ 题意:从一堆石头里任选两个石头s1,s2, ...

  8. Dockerfile优化建议

    1. 减少镜像层 一次RUN指令形成新的一层,尽量Shell命令都写在一行,减少镜像层. 2. 优化镜像大小:清理无用数据 一次RUN形成新的一层,如果没有在同一层删除,无论文件是否最后删除,都会带到 ...

  9. video 的使用

    video ui给了默认的暂停图片 利用video自身的属性很难达到效果  这里自己写了个 简单记录下 <div class="cg-container video-img" ...

  10. 如何在Mac OS X中开启或关闭显示隐藏文件命令

    打开终端,输入:defaults write com.apple.finder AppleShowAllFiles -bool true 此命令显示隐藏文件defaults write com.app ...