在 animateAlongsideTransition 块内对 UIImage 进行交叉溶解
Doing a cross dissolve on a UIImage inside a animateAlongsideTransition block
我已将动画添加到 UINavigationController
过渡,其中涉及重新定位 UIImageView
:
transitionCoordinator()?.animateAlongsideTransition({ context in
UIView.performWithoutAnimation {
// ...
}
// ...
myImageView.frame = newFrame
}, completion: {
// ...
})
此代码位于 viewWillAppear(_:)
中。这段代码到目前为止工作正常。但是,我不只是想更改图像视图的框架,我还想使用交叉溶解来更改图像。我试过这个:
transitionCoordinator()?.animateAlongsideTransition({ context in
UIView.performWithoutAnimation {
// ...
}
// ...
myImageView.frame = newFrame
UIView.transitionWithView(boardImageView,
duration: context.transitionDuration(),
options: .TransitionCrossDissolve,
animations: {
myImageView.image = newImage
}, completion: nil)
}, completion: {
// ...
})
虽然这不起作用 - 它只是在动画完成后更改图像视图的图像(没有交叉溶解)。有没有办法在过渡期间进行交叉溶解?
只需手动执行转换会完成的操作。在 animateAlongsideTransition
调用之前,将新的图像视图放入界面中与旧图像视图相同的位置,alpha
为 0
。在动画中,将其 alpha
更改为 1
并将旧图像视图的 alpha
更改为 0
,从而可以明显地执行交叉溶解。 (当然,也可以在这里做任何其他动画。)在完成块中,删除旧的(现在不可见的)图像视图。
我已将动画添加到 UINavigationController
过渡,其中涉及重新定位 UIImageView
:
transitionCoordinator()?.animateAlongsideTransition({ context in
UIView.performWithoutAnimation {
// ...
}
// ...
myImageView.frame = newFrame
}, completion: {
// ...
})
此代码位于 viewWillAppear(_:)
中。这段代码到目前为止工作正常。但是,我不只是想更改图像视图的框架,我还想使用交叉溶解来更改图像。我试过这个:
transitionCoordinator()?.animateAlongsideTransition({ context in
UIView.performWithoutAnimation {
// ...
}
// ...
myImageView.frame = newFrame
UIView.transitionWithView(boardImageView,
duration: context.transitionDuration(),
options: .TransitionCrossDissolve,
animations: {
myImageView.image = newImage
}, completion: nil)
}, completion: {
// ...
})
虽然这不起作用 - 它只是在动画完成后更改图像视图的图像(没有交叉溶解)。有没有办法在过渡期间进行交叉溶解?
只需手动执行转换会完成的操作。在 animateAlongsideTransition
调用之前,将新的图像视图放入界面中与旧图像视图相同的位置,alpha
为 0
。在动画中,将其 alpha
更改为 1
并将旧图像视图的 alpha
更改为 0
,从而可以明显地执行交叉溶解。 (当然,也可以在这里做任何其他动画。)在完成块中,删除旧的(现在不可见的)图像视图。