"神奇移动"影响自定义转换 [英] "Magic Move" Effect Custom Transition

查看:164
本文介绍了"神奇移动"影响自定义转换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图让两个View控制器之间的自定义转换。首先,这里有一个图片来说明我想要什么:

I trying to get a custom transition between two View Controllers. First, here's a picture to illustrate what I want :

我要UICollectionViewCell扩展到整个屏幕。在这个单元中,子视图在IB放置自动布局。

I want a UICollectionViewCell to expand to the whole screen. In this cell, the subviews are placed with Autolayout in IB.

我只是希望每个子视图转到新的位置。所以,我想 subview.frame = newSubview.frame 在动画块,但它不工作(因为自动布局的我认为)。

I just want each subview to go to the new position. So I tried subview.frame = newSubview.frame in the animation block, but it doesn't work (because of Autolayout I think).

我想删除,而动画正在发生的约束,但它不工作。

I thought to delete the constraints while the animation is occuring, but it doesn't work.

我也试图使约束@IBOutlets并改变恒定属性。

I also tried to make @IBOutlets of the constraints and to change constant property.

下面是我的code:

    let detailView = detailViewController.view
    let cellView = self.selectedCell

    container.addSubview(cellView!)

    let duration = self.transitionDuration(transitionContext)

    UIView.animateWithDuration(duration, delay: 0.0, options: .CurveEaseInOut, animations: {

            let newFrame = detailViewController.view.frame
            cellView!.frame = newFrame
            cellView!.imageView.frame = newFrame
            cellView!.labelTopConstraint.constant = 27
            cellView!.labelRightConstraint.constant = 8
            cellView!.layoutIfNeeded()
        }

...

实际上,当在动画开始标签捕捉到的位置上,然后它们移动和在结束时,他们都没有在正确的位置上...

Actually, when the animation begins the labels snap to a position, then they move and at the end they are not at the right position...

任何想法?谢谢

推荐答案

看看这个回购协议,我认为这是你在找什么BCMagicTransition:的 https://github.com/boycechang/BCMagicTransition

Check out this repo, I think this is what you are looking for BCMagicTransition: https://github.com/boycechang/BCMagicTransition

与code的问题是,你是不是转换要动画过渡的容器视图控制器的坐标你对你的集合视图细胞子视图的框架,并与最终的相同帧为自己的立场。即使您正在使用自动版式你仍然可以操纵他们的框架意见。

The issue with your code is that you aren't converting the frames of your subviews of your collection view cell that you want to animate to the coordinates of the container view controller of the transition, and same with the final frames for their positions. Even though you are using AutoLayout you can still manipulate views with their frames.

要做到这一点,结账这种方法(<一个href=\"https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIView_Class/index.html#//apple_ref/occ/instm/UIView/convertRect:fromView:\"相对=nofollow>文档):

To accomplish this, checkout this method (documentation):

        func convertRect(rect: CGRect, fromView view: UIView?) -> CGRect

您也应该看看动画的希望动画的意见快照。然后,只需添加快照到容器视图,并以动画转换的最终框架,然后删除它们在动画完成时。

You also should look into animating snapshots of the views you wish to animate. Then just add the snapshots to the container view, and animate them to the converted final frames, then remove them when the animation is complete.

希望这有助于!

这篇关于&QUOT;神奇移动&QUOT;影响自定义转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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