我有一个小设置,我将 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/