iOS转场动画初探
一般我们就用两种转场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转场动画初探的更多相关文章
- iOS 转场动画探究(一)
什么是转场动画: 转场动画说的直接点就是你常见的界面跳转的时候看到的动画效果,我们比较常见的就是控制器之间的Push和Pop,还有Present和Dismiss的时候设置一下系统给我们的modalTr ...
- iOS 转场动画探究(二)
这篇文章是接着第一篇写的,要是有同行刚看到的话建议从前面第一篇看,这是第一篇的地址:iOS 转场动画探究(一) 接着上一篇写的内容: 上一篇iOS 转场动画探究(一)我们说到了转场要素的第四点,把那个 ...
- iOS转场动画
文顶顶 最怕你一生碌碌无为 还安慰自己平凡可贵 iOS开发UI篇—核心动画(转场动画和组动画) iOS开发UI篇—核心动画(转场动画和组动画) 一.转场动画简单介绍 CAAnimation的子类,用于 ...
- iOS转场动画封装
写在前面 iOS在modal 或push等操作时有默认的转场动画,但有时候我们又需要特定的转场动画效果,从iOS7开始,苹果就提供了自定义转场的API,模态推送present和dismiss.导航控制 ...
- iOS - 转场动画
苹果在 iOS7 定制了 ViewController 的切换效果 一 在iOS5和iOS6之前,ViewController的切换主要有4种 Push/Pop,NavigationViewCotnr ...
- iOS 转场动画核心内容
CATransition——转场动画 CATransition是CAAnimation的子类,用于做转场动画,能够为层提供移出屏幕和移入屏幕的动画效果.iOS比Mac OS X的转场动画效果少一点. ...
- IOS 转场动画二和透明控制器视图
一.透明视图控制器 WJListMenuViewController *VC = [[WJListMenuViewController alloc]init]; VC.modalPresentatio ...
- iOS开发UI篇—核心动画(转场动画和组动画)
转自:http://www.cnblogs.com/wendingding/p/3801454.html iOS开发UI篇—核心动画(转场动画和组动画) 一.转场动画简单介绍 CAAnimation的 ...
- iOS 开发--转场动画
"用过格瓦拉电影,或者其他app可能都知道,一种点击按钮用放大效果实现转场的动画现在很流行,效果大致如下:" 本文主讲SWIFT版,OC版在后面会留下Demo下载 在iOS中,在同 ...
随机推荐
- 洛谷 P2617 Dynamic Ranking
题目描述 给定一个含有n个数的序列a[1],a[2],a[3]……a[n],程序必须回答这样的询问:对于给定的i,j,k,在a[i],a[i+1],a[i+2]……a[j]中第k小的数是多少(1≤k≤ ...
- Java面试题全集(下)
这部分主要是开源Java EE框架方面的内容,包括hibernate.MyBatis.spring.Spring MVC等,由于Struts 2已经是明日黄花,在这里就不讨论Struts 2的面试题, ...
- 从汇编看c++中的多态
http://www.cnblogs.com/chaoguo1234/archive/2013/05/19/3079078.html 在c++中,当一个类含有虚函数的时候,类就具有了多态性.构造函数的 ...
- Xcode编译工具
一.关于Other Linker Flags xcode中,在“Targets”选项下有Other Linker Flags选项,在这里可以填写xcode链接器的参数,如:-ObjC.-all_loa ...
- Scroller 界面滑动
Scroller 滑动之后滑动器子标签里面的控件,其自身是不动的.这里点在下面的进阶会体现出来. 1. 继承LinearLayout, 相对布局也可以. public class MyLinearL ...
- BZOJ1009: [HNOI2008]GT考试 (矩阵快速幂 + DP)
题意:求一个长度为n的数字字符串 (n <= 1e9) 不出现子串s的方案数 题解:用f i,j表示长度为i匹配到在子串j的答案 用kmp的失配函数预处理一下 然后这个转移每一个都是一样的 所以 ...
- struts2的动态方法配置
动态方法调用配置 <package name="test" extends="struts-default"> <aciton name=&q ...
- iterator方法和for方法 遍历数据库user表结果集ResultSet
首先,把连接数据库的语句做成工具类,因为会一直用到这几句 代码如下: package com.swift.jdbc; import java.sql.Connection; import java.s ...
- C++系统学习之四:数组
与vector的异同 相同:都是存放类型相同对象的容器 不同:数组的大小确定不变,不能随意向数组中增加元素 1.定义和初始化内置数组 数组中元素的个数也属于数组类型的一部分,编译的时候维度应该是已知的 ...
- HDU-2544-最短路(floyd)
板子题,实验一下floyd. #include <cstdio> #include <algorithm> #include <cstring> using nam ...