ios - Swift Zoom Transition Animation 仅在第二次不起作用

标签 ios swift animation uiviewanimation uiviewanimationtransition

我创建了自定义过渡 NSZoomTransitionAnimator。

我有一个问题,即仅在第二次返回时转换不起作用。

例如,我在 Collection View 中触摸了一个单元格 (indexPath.row = 0)。第一次工作正常,但第二次工作不正常。

我调试代码,第二次发现sourceImageView.frame是(0.0, 0.0, 360.0, 480.0)。

(0.0, 0.0, 360.0, 480.0) 是正确的。

这是我的代码,NSZoomTransitionAnimator.swift。

UIView.animateWithDuration(kBackwardAnimationDuration, delay: 0, options: .CurveEaseOut, animations: {
  sourceImageView.frame = destinationImageViewFrame
  println(sourceImageView.frame)//(0.0, 64.0, 187.5, 187.5)

}, completion: {(finished: Bool) in
  if finished {
      destinationImageView.removeFromSuperview()

      println(sourceImageView.frame)//(0.0, 0.0, 360.0, 480.0)
      sourceImageView.removeFromSuperview()
  }
  transitionContext.completeTransition(finished)
})

这是我的仓库。
https://github.com/naoyashiga/NSZoomTransitionAnimator

触摸 Collection View 中的图像并触摸 DetailViewController 中的关闭按钮。因此过渡将开始。

请告诉我为什么只有第二次转换不工作。

最佳答案

您不能重复使用具有两个约束的 sourceViewController.transitionSourceImageView():

(lldb) po sourceImageView.constraints()
[
<NSContentSizeLayoutConstraint:0x7feaeb7097a0 H:[UIImageView:0x7feaeb577230(360)] Hug:251 CompressionResistance:750>, 
<NSContentSizeLayoutConstraint:0x7feaeb704680 V:[UIImageView:0x7feaeb577230(480)] Hug:251 CompressionResistance:750>
]

所以它的大小将不正确。相反,您可以更改

sourceImageView = sourceViewController.transitionSourceImageView()

sourceImageView.image = sourceViewController.transitionSourceImageView().image
sourceImageView.frame = sourceViewController.transitionSourceImageView().frame

这将解决您的问题。

关于ios - Swift Zoom Transition Animation 仅在第二次不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31099173/

相关文章:

ios - 是否可以在 UIDynamicKit 中模拟对象/UIView 的重力?

ios - 协议(protocol)委托(delegate)未按预期传递数据 [Swift5]

java - 多种语言的随机数

javascript - 为什么滚动动画没有被禁用?

xcode - iOS将已编译的捆绑软件添加到模拟器

ios - 并发症图像是白框 - watchOS 2 ClockKit

ios - 搜索核心数据中的关系数量 - Swift

ios - CLLocationManager 的 startMonitoringSignificantLocationChanges() 和 startUpdatingLocation() 方法有什么区别?

java - GIF 作为 JFrame 的背景

android - 配置更改后 fragment 丢失过渡动画