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实现之前, ...
随机推荐
- 基于DDDLite的权限管理OpenAuth.net 1.0版正式发布
距离上一篇OpenAuth.net的文章已经有5个多月了,在这段时间里项目得到了很多朋友的认可,开源中国上面的Star数接近300,于是坚定了我做下去的信心.最近稍微清闲点,正式推出1.0版,并在阿里 ...
- Fedora 22中的用户和用户组管理
The control of users and groups is a core element of Fedora system administration. This chapter expl ...
- ASP.NET MVC Model绑定(一)
ASP.NET MVC Model绑定(一) 前言 ModelMetadata系列的结束了,从本篇开始就进入Model绑定部分了,这个系列阅读过后你会对Model绑定有个比较清楚的了解, 本篇对于Mo ...
- ABP教程-给项目添加SwaggerUI,生成动态webapi
上一篇,我们是正式将ABP生成的代码项目,跑起来了,然后演示了下多租户的不同.那么这篇我们就来实现下SwaggerUI. Q:SwaggerUI是干什么的呢? A:他是一个能将我们的webapi,通过 ...
- 反编译.NET工程
工具: 1. .Net Reflector 2. 远程桌面 步骤: 1. 远程桌面连接到服务器 IP,port,user,pwd 2. 打开 IIS 这里面就是所部属的网 ...
- 【原】得心应手小工具开发——IE代理快速切换工具
一.引入 因为公司里上外网要经常换IE代理地址,每次切换地址都要进到Internet Options里去设置一番,经常切换的话很是麻烦,由于用了点时间作个小工具来方便自己. 二.实现思路 其实思路很简 ...
- AOP概述
了解AOP之前,先大概讲述一下SOC: Soc:Separation of concerns 关注分离点, 在不同的场景SOC有着不同的含义 Soc是一个过程:Soc是一个将功能点分解以尽量减小功能交 ...
- MVC5 网站开发之六 管理员 2、添加、删除、重置密码、修改密码、列表浏览
目录 奔跑吧,代码小哥! MVC5网站开发之一 总体概述 MVC5 网站开发之二 创建项目 MVC5 网站开发之三 数据存储层功能实现 MVC5 网站开发之四 业务逻辑层的架构和基本功能 MVC5 网 ...
- 计算机程序的思维逻辑 (44) - 剖析TreeSet
41节介绍了HashSet,我们提到,HashSet有一个重要局限,元素之间没有特定的顺序,我们还提到,Set接口还有另一个重要的实现类TreeSet,它是有序的,与HashSet和HashMap的关 ...
- php-resque的设计和使用
php-resque-1.2-annotated 一个 php-resque 源码阅读的项目,欢迎大家star php-resque的设计 在Resque中,一个后台任务被抽象为由三种角色共同完成: ...