OC转场动画UIViewControllerTransitioningDelegate
该项目一共两个界面,第一个的只有一个SystemAnimationViewController只有UICollecitonView,第二个界面ImgDetailViewController只有一个UIImageView,代码简单,这里不做陈述
下面是转场动画的所有代码:
//
// ModelAnimationDelegate.m
// Demo
//
// Created by Apple on 2018/11/8.
// Copyright © 2018年 cqytjr. All rights reserved.
// #import "ModelAnimationDelegate.h"
#import "SystemAnimationViewController.h"
#import "SystemAnimaitonCollectionViewCell.h"
#import "ImgDetailViewController.h"
/*
1.描述ViewController转场的:
UIViewControllerTransitioningDelegate自定义模态转场动画时使用
,UINavigationControllerDelegate 自定义navigation转场动画时使用。,
UITabBarControllerDelegate 自定义tab转场动画时使用。
2.定义动画内容的
UIViewControllerAnimatedTransitioning,UIViewControllerInteractiveTransitioning
3.表示动画上下文的
UIViewControllerContextTransitioning
*/
@interface ModelAnimationDelegate ()< UIViewControllerAnimatedTransitioning,UIViewControllerTransitioningDelegate>
@property (nonatomic, assign) BOOL isPresentAnimationing;
@end @implementation ModelAnimationDelegate #pragma mark UIViewControllerAnimatedTransitioning // 视图弹出
- (void)presentViewAnimation:(id <UIViewControllerContextTransitioning>)transitionContext { // 获取容器view
UIView *containerView = [transitionContext containerView];
// 获取目标view
UIView *destinationView = [transitionContext viewForKey:UITransitionContextToViewKey];
destinationView.alpha = 0;
// 将目标view添加到容器view
[containerView addSubview:destinationView]; // 获取目标vc
ImgDetailViewController *destinationVC = [transitionContext viewControllerForKey:UITransitionContextToViewControllerKey];
NSIndexPath *indexPath = destinationVC.indexPath; // 获取来源vc
UINavigationController *naVC = [transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey];
SystemAnimationViewController *sourceVC = (SystemAnimationViewController *)naVC.topViewController;
// 获取来源view
UICollectionView *collectionView = sourceVC.collectionView;
SystemAnimaitonCollectionViewCell *selectedCell = (SystemAnimaitonCollectionViewCell *)[collectionView cellForItemAtIndexPath:indexPath];
// 获取动画开始位置大小
CGRect startFrame = [collectionView convertRect:selectedCell.frame toView:[UIApplication sharedApplication].keyWindow]; UIImageView *animationImgView = [[UIImageView alloc] initWithFrame:startFrame];
animationImgView.image = selectedCell.img.image;
animationImgView.contentMode = UIViewContentModeScaleAspectFit;
animationImgView.clipsToBounds = YES;
[containerView addSubview:animationImgView]; // 获取动画结束位置大小
CGRect endFrame = destinationVC.img.frame; // 执行过渡动画
[UIView animateWithDuration:1.0 animations:^{
animationImgView.frame = endFrame;
NSLog(@"-----:%f %f %f %f",startFrame.origin.x,startFrame.origin.y,startFrame.size.width,startFrame.size.height);
NSLog(@"-----:%f %f %f %f",endFrame.origin.x,endFrame.origin.y,endFrame.size.width,endFrame.size.height); } completion:^(BOOL finished) {
[transitionContext completeTransition:YES];
[UIView animateWithDuration:1.0 animations:^{
destinationView.alpha = 1.0;
} completion:^(BOOL finished) {
[animationImgView removeFromSuperview];
}];
}]; } // 视图消失
- (void)dismissViewAnimation:(id <UIViewControllerContextTransitioning>)transitionContext { // 获取容器view
UIView *containerView = [transitionContext containerView];
// 获取目标view
UIView *destinationView = [transitionContext viewForKey:UITransitionContextToViewKey];
destinationView.alpha = 0;
// 将目标view添加到容器view
[containerView addSubview:destinationView]; UINavigationController *naVC = [transitionContext viewControllerForKey:UITransitionContextToViewControllerKey];
// 获取目标vc
SystemAnimationViewController *destinationVC = naVC.topViewController;
// NSIndexPath *indexPath = destinationVC.indexPath;
//
// 获取来源vc ImgDetailViewController *sourceVC = (ImgDetailViewController *)[transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey];
NSIndexPath *indexPath = sourceVC.indexPath;
// 获取来源view
UICollectionView *collectionView = destinationVC.collectionView;
SystemAnimaitonCollectionViewCell *selectedCell = (SystemAnimaitonCollectionViewCell *)[collectionView cellForItemAtIndexPath:indexPath]; // 获取动画开始位置大小
CGRect startFrame = sourceVC.img.frame; UIImageView *animationImgView = [[UIImageView alloc] initWithFrame:startFrame];
animationImgView.image = selectedCell.img.image;
animationImgView.contentMode = UIViewContentModeScaleAspectFill;
animationImgView.clipsToBounds = YES;
[containerView addSubview:animationImgView];
animationImgView.contentMode = UIViewContentModeScaleAspectFit;
animationImgView.clipsToBounds = YES; // 获取动画结束位置大小
CGRect endFrame = [collectionView convertRect:selectedCell.frame toView:[UIApplication sharedApplication].keyWindow]; // 执行过渡动画
[UIView animateWithDuration:1.0 animations:^{
animationImgView.frame = endFrame; NSLog(@"-----:%f %f %f %f",startFrame.origin.x,startFrame.origin.y,startFrame.size.width,startFrame.size.height);
NSLog(@"-----:%f %f %f %f",endFrame.origin.x,endFrame.origin.y,endFrame.size.width,endFrame.size.height);
sourceVC.view.hidden = YES; } completion:^(BOOL finished) {
[transitionContext completeTransition:YES]; }];
[UIView animateWithDuration:1.0 animations:^{
destinationView.alpha = 1.0; } completion:^(BOOL finished) {
[animationImgView removeFromSuperview];
}];
} - (NSTimeInterval)transitionDuration:(nullable id <UIViewControllerContextTransitioning>)transitionContext {
return 10.0;
} - (void)animateTransition:(id <UIViewControllerContextTransitioning>)transitionContext {
_isPresentAnimationing ? [self presentViewAnimation:transitionContext] : [self dismissViewAnimation:transitionContext]; } #pragma mark UIViewControllerTransitioningDelegate - (nullable id <UIViewControllerAnimatedTransitioning>)animationControllerForPresentedController:(UIViewController *)presented presentingController:(UIViewController *)presenting sourceController:(UIViewController *)source {
_isPresentAnimationing = YES;
return self;
} - (nullable id <UIViewControllerAnimatedTransitioning>)animationControllerForDismissedController:(UIViewController *)dismissed {
_isPresentAnimationing = NO;
return self; } @end
OC转场动画UIViewControllerTransitioningDelegate的更多相关文章
- 教你实现类似于格瓦拉启动页中的放大转场动画(OC&Swift)
教你实现类似于格瓦拉启动页中的放大转场动画(OC&Swift) 一.前言 用过格瓦拉电影,或者其他app可能都知道,一种点击按钮用放大效果实现转场的动画现在很流行,效果大致如下 在iOS中,在 ...
- 自己定义转场动画--Swift3.0版本号
转场动画这事.说简单也简单.能够通过presentViewController:animated:completion:和dismissViewControllerAnimated:completio ...
- iOS自定义转场动画实战讲解
iOS自定义转场动画实战讲解 转场动画这事,说简单也简单,可以通过presentViewController:animated:completion:和dismissViewControllerA ...
- Swift开发小技巧--自定义转场动画
自定义转场动画 个人理解为重写了被弹出控制器的modal样式,根据自己的样式来显示modal出来的控制器 例:presentViewController(aVC, animated: true, co ...
- iOS 开发--转场动画
"用过格瓦拉电影,或者其他app可能都知道,一种点击按钮用放大效果实现转场的动画现在很流行,效果大致如下:" 本文主讲SWIFT版,OC版在后面会留下Demo下载 在iOS中,在同 ...
- 类似nike+、香蕉打卡的转场动画效果-b
首先,支持并感谢@wazrx 的 http://www.jianshu.com/p/45434f73019e和@onevcat 的https://onevcat.com/2013/10/vc-tran ...
- iOS 转场动画探究(一)
什么是转场动画: 转场动画说的直接点就是你常见的界面跳转的时候看到的动画效果,我们比较常见的就是控制器之间的Push和Pop,还有Present和Dismiss的时候设置一下系统给我们的modalTr ...
- iOS 转场动画探究(二)
这篇文章是接着第一篇写的,要是有同行刚看到的话建议从前面第一篇看,这是第一篇的地址:iOS 转场动画探究(一) 接着上一篇写的内容: 上一篇iOS 转场动画探究(一)我们说到了转场要素的第四点,把那个 ...
- iOS转场动画封装
写在前面 iOS在modal 或push等操作时有默认的转场动画,但有时候我们又需要特定的转场动画效果,从iOS7开始,苹果就提供了自定义转场的API,模态推送present和dismiss.导航控制 ...
随机推荐
- win7下安装Office2010老是出现提示安装MSXML6.10.1129.0,下载官方MSXML后提示安装成功却也安装不了
在注册表中增加以下信息: [HKEY_CLASSES_ROOT\TypeLib\{F5078F18-C551-11D3-89B9-0000F81FE221}][HKEY_CLASSES_ROOT\Ty ...
- CentOS7 yum方式安装MariaDB 10.2.13-1
注:以下步骤都是以root身份运行. 一.建立mariadb.repo 1,编辑新文件,命令:vim /etc/yum.repos.d/mariadb.repo 2,输入如下内容,保存退出 [mar ...
- HTML jQuery实现的expend row
问 题:今天接到个任务,在一个老的系统页面里实现可展开的表格行. 寻找: 1.首先想到了在easyUI里见过的expand row form: 2.但是我们的老系统管理只有jQuery,如果使用eas ...
- MTK 自定义按键添加广播
一.给自定义按键添加广播 修改PhoneWindowManager.java中的interceptKeyBeforeDispatching方法 /frameworks/base/policy/src/ ...
- [JS] ECMAScript 6 - String, Number, Function : compare with c#
字符串的扩展 正则的扩展 数值的扩展 函数的扩展 字符串的扩展 js 字符的 Unicode 表示法 codePointAt() String.fromCodePoint() 字符串的遍历器接口 at ...
- 我的Mac Pro coding环境配置
新装了OS X 10.11.1. 记录一下开发用得到的一些玩意,方便下次再次配置. homebrew国内源:http://mirrors.tuna.tsinghua.edu.cn/help/#home ...
- Android图片管理组件(双缓存+异步加载)
转自:http://www.oschina.net/code/snippet_219356_18887?p=3#comments ImageManager2这个类具有异步从网络下载图片,从sd读取本地 ...
- A - 取(m堆)石子游戏
m堆石子,两人轮流取.只能在1堆中取.取完者胜.先取者负输出No.先取者胜输出Yes,然后输出怎样取子.例如5堆 5,7,8,9,10先取者胜,先取者第1次取时可以从有8个的那一堆取走7个剩下1个,也 ...
- angular.js学习笔记--概念总结
好久没更新了,现在开始学习学习angularjs,并且把学习到的一些知识总结记录一下,方便以后查找以及希望能给初学者一些帮助!(由于本人也是初学ng所以各位慎重理解!) 废话不多说,开始! $root ...
- 爬虫----爬虫请求库requests
一 介绍 介绍:---------------------------------------------使用requests可以模拟浏览器的请求,比起之前用到的urllib,requests模块的a ...