ios - Swift:从 subview 中删除发生在动画之前

标签 ios animation swift jquery-animate

我有一个小设置,我将 MPMoviePlayerController 设置为视频背景。我试图让它在更新/更改时平稳过渡。这是我当前的代码。顺便说一句,newBackground.view.alpha 最初是 0。

let oldBackground = currentBackground

self.view.insertSubview(newBackground.view, aboveSubview: oldBackground.view)
  UIView.animateWithDuration(1.5 as NSTimeInterval, animations: {
    newBackground.view.alpha = 1
    }, completion: {
      finished in
      oldBackground.view.removeFromSuperview()
      println("The subview should be removed now")
  })

执行时,oldBackground.view 在 newBackground 开始淡入之前立即被删除。然而,println 发生在动画完成之后。我不明白为什么 removeFromSuperview 会立即发生,但 println 在我期望的时候发生。如果我删除 oldBackground.view.removeFromSuperview(),动画淡入并且看起来不错(但 View 显然没有被删除,它只是位于 newBackground 后面)。

编辑:奇怪的是,它似乎在模拟器中按预期工作。在我的 iPhone 6 Plus 上运行每次都会给我这个问题。我已从 Xcode 卸载并重新运行它,但问题仍然存在。

如果有人对我有任何建议,我会很高兴。谢谢。

最佳答案

我想当 newBackground.view.alpha = 1 在动画期间执行时,它会使背景可见并覆盖 oldBackground。

关于ios - Swift:从 subview 中删除发生在动画之前,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27464254/

相关文章:

ios - 如何在设备上的每个触摸位置周围绘制一个圆圈?

ios - UICollectionView 水平滚动,删除最后一项,动画不工作

swift - 为什么我需要转换这个通用返回值?

ios - Google Analytics Swift - 不显示更新的仪表板报告

ios - UITextField 委托(delegate) "shouldChangeCharactersIn"未调用文本字段中的第一个条目

javascript - jquery根据响应延迟进程

cocoa-touch - UILabel 的动画框架平滑

iphone - 从不同的 View Controller 调用时,UIView 动画不会触发?

arrays - 如何从字符串数组中获取文本并将其用作按钮的文本?

ios - 如何知道 iOS 中是否显示了位置服务对话框?