UIViewControllerTransitioningDelegate, UIViewControllerAnimatedTransitioning
#import "ModelAnimationDelegate.h"
#import <UIKit/UIKit.h>
#import "MapVC.h"
#import "MapLiuLanViewController.h"
#import "MapCollectionViewCell.h" @interface ModelAnimationDelegate ()<UIViewControllerTransitioningDelegate, UIViewControllerAnimatedTransitioning> @property (nonatomic, assign) BOOL isPresentAnimationing; @end @implementation ModelAnimationDelegate // 视图弹出
- (void)presentViewAnimation:(id <UIViewControllerContextTransitioning>)transitionContext {
// 获取容器view
UIView *containerView = [transitionContext containerView];
// 获取目标view
UIView *destinationView = [transitionContext viewForKey:UITransitionContextToViewKey];
destinationView.alpha = ;
// 将目标view添加到容器view
[containerView addSubview:destinationView]; // 获取目标vc
MapLiuLanViewController *destinationVC = [transitionContext viewControllerForKey:UITransitionContextToViewControllerKey];
NSIndexPath *indexPath = destinationVC.indexPath; // 获取来源vc
UINavigationController *naVC = [transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey];
MapVC *sourceVC = (MapVC *)naVC.topViewController;
// 获取来源view
UICollectionView *collectionView = sourceVC.collectionView;
MapCollectionViewCell *selectedCell = (MapCollectionViewCell *)[collectionView cellForItemAtIndexPath:indexPath]; // 获取动画开始位置大小
CGRect startFrame = [collectionView convertRect:selectedCell.frame toView:[UIApplication sharedApplication].keyWindow]; UIImageView *animationImgView = [[UIImageView alloc] initWithFrame:startFrame];
animationImgView.image = selectedCell.imgView.image;
animationImgView.contentMode = UIViewContentModeScaleAspectFill;
animationImgView.clipsToBounds = YES;
[containerView addSubview:animationImgView]; // 获取动画结束位置大小
CGFloat w = WIDTH;
CGFloat h = w / animationImgView.image.size.width * animationImgView.image.size.height;
CGFloat x = ;
CGFloat y = (HEIGHT - h) / 2.0;
CGRect endFrame = CGRectMake(x, y, w, h); // 执行过渡动画
[UIView animateWithDuration:1.0 animations:^{
animationImgView.frame = endFrame;
} completion:^(BOOL finished) {
[transitionContext completeTransition:YES];
[UIView animateWithDuration:0.5 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 = ;
// 将目标view添加到容器view
[containerView addSubview:destinationView]; // 获取目标vc
MapLiuLanViewController *destinationVC = [transitionContext viewControllerForKey:UITransitionContextToViewControllerKey];
NSIndexPath *indexPath = destinationVC.indexPath; // 获取来源vc
UINavigationController *naVC = [transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey];
MapVC *sourceVC = (MapVC *)naVC.topViewController;
// 获取来源view
UICollectionView *collectionView = sourceVC.collectionView;
MapCollectionViewCell *selectedCell = (MapCollectionViewCell *)[collectionView cellForItemAtIndexPath:indexPath]; // 获取动画开始位置大小
CGRect startFrame = [collectionView convertRect:selectedCell.frame toView:[UIApplication sharedApplication].keyWindow]; UIImageView *animationImgView = [[UIImageView alloc] initWithFrame:startFrame];
animationImgView.image = selectedCell.imgView.image;
animationImgView.contentMode = UIViewContentModeScaleAspectFill;
animationImgView.clipsToBounds = YES;
[containerView addSubview:animationImgView]; // 获取动画结束位置大小
CGFloat w = WIDTH;
CGFloat h = w / animationImgView.image.size.width * animationImgView.image.size.height;
CGFloat x = ;
CGFloat y = (HEIGHT - h) / 2.0;
CGRect endFrame = CGRectMake(x, y, w, h); // 执行过渡动画
[UIView animateWithDuration:1.0 animations:^{
animationImgView.frame = endFrame;
} completion:^(BOOL finished) {
[transitionContext completeTransition:YES];
[UIView animateWithDuration:0.5 animations:^{
destinationView.alpha = 1.0;
} completion:^(BOOL finished) {
[animationImgView removeFromSuperview];
}];
}];
} #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;
} #pragma mark ----- UIViewControllerAnimatedTransitioning协议方法 ----- - (NSTimeInterval)transitionDuration:(nullable id <UIViewControllerContextTransitioning>)transitionContext {
return 1.0;
} - (void)animateTransition:(id <UIViewControllerContextTransitioning>)transitionContext {
_isPresentAnimationing ? [self presentViewAnimation:transitionContext] : [self dismissViewAnimation:transitionContext];
} @end
UIViewControllerTransitioningDelegate, UIViewControllerAnimatedTransitioning的更多相关文章
- iOS - UISearchController
前言 NS_CLASS_DEPRECATED_IOS(3_0, 8_0, "UISearchDisplayController has been replaced with UISearch ...
- 【Swift】UIPresentationController的使用方法
UIPresentationController是ios8.0的新特性哦,使用需要注意 先上一个效果图 第一步: 连线选择segue类型为,present Modally 第二步:需要演示的控制器,自 ...
- OC转场动画UIViewControllerTransitioningDelegate
该项目一共两个界面,第一个的只有一个SystemAnimationViewController只有UICollecitonView,第二个界面ImgDetailViewController只有一个UI ...
- 实现放大转场动画 from cocoachina
原文1:http://www.cocoachina.com/ios/20160318/15714.html 原文2:http://ningandjiao.iteye.com/blog/2049105 ...
- iOS(视图控制器转场)
转场需要提供转场代理,不使用默认的代理则需要自己实现代理方式,有UINavigationController.UITabBarController.UIViewController三种代理,实现以下三 ...
- OC中UITabBarController控制器
UITabBarController UITabBarController(记为O)常用于管理多个导航控制器,例如有ABC三个导航控制器,可以:addChildViewController(记为A), ...
- Swift开发小技巧--自定义转场动画
自定义转场动画 个人理解为重写了被弹出控制器的modal样式,根据自己的样式来显示modal出来的控制器 例:presentViewController(aVC, animated: true, co ...
- swift项目初体验--教你打造一款个性化图片浏览器(篇幅过大,慎入)
项目需求:做一个图片浏览器,点击图片查看大图,大图模式下,左右滚动能查看不同的图片. 项目的主要核心技术:图片的弹出和消失动画 项目源代码: Photo-Browser 一.对代码进行重构 ...
- iOS7中的ViewController切换
转自:https://onevcat.com/2013/10/vc-transition-in-ios7/ iOS 7 SDK之前的VC切换解决方案 在深入iOS 7的VC切换效果的新API实现之前, ...
随机推荐
- mono for android Json 上传文件
void button_Click(object sender, EventArgs e) { string Url = "上传地址,服务器端负责接收"; byte[] fbyte ...
- Jquery双向select控件Bootstrap Dual Listbox
效果预览: 一. 下载插件 github地址:https://github.com/istvan-ujjmeszaros/bootstrap-duallistbox 也可以在这个网站中下载:http: ...
- CSharpGL(23)用ComputeShader实现一个简单的ParticleSimulator
CSharpGL(23)用ComputeShader实现一个简单的ParticleSimulator 我还没有用过Compute Shader,所以现在把红宝书里的例子拿来了,加入CSharpGL中. ...
- Android开发之Android Material Design Toolbar自定义随笔
一.自定义Toolbar的menu: 在menu下新建menu.xml文件,自定义menu的样式: <menu xmlns:android="http://schemas.androi ...
- webpack入门教程之初识loader(二)
上一节我们学习了webpack的安装和编译,这一节我们来一起学习webpack的加载器和配置文件. 要想让网页看起来绚丽多彩,那么css就是必不可少的一份子.如果想要在应用中增加一个css文件,那么w ...
- windows7 下 apache2.4 和 php5.5 及 mysql5.6 的安装与配置
要准备的软件 httpd-2.4.9-win32-VC11.zip http://www.apachelounge.com/download/ php-5.5.13-Win32-VC11-x86.zi ...
- mysql数据库开发常见问题及优化
mysql 数据库是被广泛应用的关系型数据库,其体积小.支持多处理器.开源并免费的特性使其在 Internet 中小型网站中的使用率尤其高.在使用 mysql 的过程中不规范的 SQL 编写.非最优的 ...
- JavaScript资源大全中文版(Awesome最新版)
Awesome系列的JavaScript资源整理.awesome-javascript是sorrycc发起维护的 JS 资源列表,内容包括:包管理器.加载器.测试框架.运行器.QA.MVC框架和库.模 ...
- 如何给现有的PDF文件添加页码
如何给现有的PDF文件添加页码 之前我写了如何打印PDF文件,有人qq问我怎样在打印时给PDF文件添加页码,的确,给PDF文件添加页码,可以帮助我们区分纸质档的PDF文件页面的先后顺序,方便我们对它的 ...
- 使用UICollectionView实现首页的滚动效果
实现类似这样的效果,可以滚动大概有两种实现方案 1. 使用scrollview来实现 2. 使用UICollectionView来实现 第一种比较简单,而且相对于性能来说不太好,于是我们使用第二种方案 ...