我已将动画添加到 UINavigationController
转换,其中涉及重新定位 UIImageView
:
transitionCoordinator()?.animateAlongsideTransition({ context in
UIView.performWithoutAnimation {
// ...
}
// ...
myImageView.frame = newFrame
}, completion: {
// ...
})
此代码位于 viewWillAppear(_:)
中。这段代码到目前为止工作正常。但是,我不只是想更改 ImageView 的框架,我还想使用交叉溶解来更改图像。我试过这个:
transitionCoordinator()?.animateAlongsideTransition({ context in
UIView.performWithoutAnimation {
// ...
}
// ...
myImageView.frame = newFrame
UIView.transitionWithView(boardImageView,
duration: context.transitionDuration(),
options: .TransitionCrossDissolve,
animations: {
myImageView.image = newImage
}, completion: nil)
}, completion: {
// ...
})
虽然这不起作用 - 它只是在动画完成后更改 ImageView 的图像(没有交叉溶解)。有没有办法在过渡期间进行交叉融合?
最佳答案
只需手动执行转换应完成的操作即可。在 animateAlongsideTransition
调用之前,将一个新的 ImageView 放入界面中与旧 ImageView 相同的位置,其中 alpha
为 0
。在动画中,将其 alpha
更改为 1
,将旧 ImageView 的 alpha
更改为 0
,这样就可以看到执行交叉溶解。 (当然,也可以在此处执行任何其他动画。)在完成 block 中,删除旧的(现在不可见的) ImageView 。
关于ios - 在 animateAlongsideTransition block 内的 UIImage 上进行交叉溶解,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35566013/