在过渡动画期间在两个视图控制器之间共享图像 [英] Sharing an Image between two viewControllers during a transition animation

查看:28
本文介绍了在过渡动画期间在两个视图控制器之间共享图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

自从 UIViewControllerAnimatedTransitioning 协议在 IOS 7 中可用以来,我在视图控制器之间遇到了非常酷的转换.最近我注意到 Intacart 的 IOS 应用程序中的一个特别有趣的转换.

这是我所说的慢动作动画:

看起来红色视图正在离开第一个视图控制器并进入第二个视图控制器,但这只是一种错觉.如果您有自定义过渡动画,则可以在过渡期间添加额外的视图.所以我创建了一个看起来和第一个视图一样的快照视图,隐藏真正的第一个视图,并移动快照视图 - 然后移除快照视图并显示真正的第二个视图.

同样的事情(我在很多应用程序中都使用了它的好技巧):看起来标题已经从第一个视图控制器表格视图单元格中脱落并滑到第二个视图控制器中,但它是只是一个快照视图:

I have came across really cool transitions between viewControllers since UIViewControllerAnimatedTransitioning protocol was made available in IOS 7. Recently I noticed a particularly interesting one in Intacart's IOS app.

Here is the animation I am talking about in slow motion: https://www.dropbox.com/s/p2hxj45ycq18i3l/Video%20Oct%2015%2C%207%2023%2059%20PM.mov?dl=0

First I thought it was similar to what the author walks through in this tutorial, with some extra fade-in and fade-out animations: http://www.raywenderlich.com/113845/ios-animation-tutorial-custom-view-controller-presentation-transitions

But then if you look at it closely, it seems like the product image transitions between the two viewControllers as the first viewController fades out. The reason why I think there are two viewControllers is because when you swipe the new view down, you can still see the original view behind it with no layout changes.

Maybe two viewControllers actually have the product image (not faded out) and are somehow animating at the same time with perfect precision and one of them fades in as the other fades out.

What do you think is actually going on there?

How is it possible to program such a transition animation that it looks like an image is shared between two viewControllers?

解决方案

It's probably two different views and an animated snapshot view. In fact, this is exactly why snapshot views were invented.

That's how I do it in my app. Watch the movement of the red rectangle as the presented view slides up and down:

It looks like the red view is leaving the first view controller and entering the second view controller, but it's just an illusion. If you have a custom transition animation, you can add extra views during the transition. So I create a snapshot view that looks just like the first view, hide the real first view, and move the snapshot view — and then remove the snapshot view and show the real second view.

Same thing here (such a good trick that I use it in a lot of apps): it looks like the title has come loose from the first view controller table view cell and slid up to into the second view controller, but it's just a snapshot view:

这篇关于在过渡动画期间在两个视图控制器之间共享图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆