“魔术移动”效果自定义转换

我试图让两个视图控制器之间的自定义过渡。 首先,这里有一张图片来说明我想要的东西:

我想要一个UICollectionViewCell扩展到整个屏幕。 在这个单元格中,子视图与Autolayout放在IB中。

我只是想让每个子视图都转到新的位置。 所以我尝试了subview.frame = newSubview.frame在animation块,但它不工作(因为Autolayout我认为)。

我想在animation发生的时候删除约束条件,但是不起作用。

我也试着让@IBOutlets的约束和改变不变的属性。

这是我的代码:

  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() } ... 

实际上,当animation开始的时候,标签会卡到一个位置,然后移动,最后它们不在正确的位置。

有任何想法吗 ? 谢谢

看看这个回购,我想这就是你正在寻找BCMagicTransition: https : //github.com/boycechang/BCMagicTransition

你的代码的问题是,你没有将你想要animation的集合视图单元格的子视图的框架转换为转换的容器视图控制器的坐标,并且与它们的位置的最终框架相同。 即使你使用AutoLayout,你仍然可以用它们的框架来操纵视图。

要做到这一点,请检查此方法( 文档 ):

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

你也应该看看你想要animation的视图的animation快照。 然后,只需将快照添加到容器视图,并将它们animation到转换的最终帧,然后在animation完成时将其删除。

希望这可以帮助 !