【问题标题】:Doing a cross dissolve on a UIImage inside a animateAlongsideTransition block在 animateAlongsideTransition 块内的 UIImage 上进行交叉溶解
【发布时间】:2016-02-22 23:33:45
【问题描述】:

我为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: {
    // ...
})

但这不起作用 - 它只是在动画完成后更改图像视图的图像(没有交叉溶解)。有没有办法在过渡期间进行交叉溶解?

【问题讨论】:

    标签: ios uiview uinavigationcontroller uiviewanimation


    【解决方案1】:

    只需手动执行过渡会完成的操作。在调用animateAlongsideTransition 之前,将一个新的图像视图放入界面与旧图像视图相同的位置,alpha0。在动画中,将其alpha更改为1,将旧图像视图的alpha更改为0,从而可见地执行交叉溶解。 (当然,在这里也可以做任何其他动画。)在完成块中,删除旧的(现在不可见的)图像视图。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-07-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-11-11
      • 1970-01-01
      • 2013-05-18
      • 2020-02-21
      相关资源
      最近更新 更多