【问题标题】:Crossfade transition dips to black when transitioning between 2 white ViewControllers在 2 个白色 ViewController 之间转换时,Crossfade 过渡变为黑色
【发布时间】:2019-04-13 06:27:42
【问题描述】:

我正在使用转场设置为交叉溶解的转场以模态方式呈现下一个视图控制器,但是尽管源 VC 和目标 VC 背景是白色的,但在转换结束时屏幕会变黑,任何方法都可以制作它浸入透明而不是黑色?

【问题讨论】:

    标签: ios objective-c uiviewanimation


    【解决方案1】:

    首先,一个好的问题应该包含您的代码或显示您遇到的问题的简化示例代码。 gif 有助于显示您所看到的内容,但如果没有代码的上下文,您将获得否决票并收到更少的答案(另外,您收到的答案主要是推测/假设,就像我的即将是)。

    我猜你看到的是动画开始和结束附近视图不透明度的变化,所以“当屏幕变黑时”你看到的是背景窗口。虽然它可能并不完美,但快速解决方法是更改​​窗口的背景颜色以匹配目标视图控制器的背景颜色(然后在转换完成后根据需要将其设置回来)。

    // within your perform method for the transition
    // hold onto the previous window background color
    UIColor *previousWindowBackgroundColor = sourceViewController.view.window.backgroundColor;
    // switch the window background color to match the destinationController's background color temporarily
    sourceViewController.view.window.backgroundColor = destinationController.view.backgroundColor;
    ...
    // perform the transition
    // switch the window color back after the transition duration from above
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(animationDuration * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        // make sure we still have a handle on the destination controller
        if (destinationController) {
            destinationController.view.window.backgroundColor = previousWindowBackgroundColor;
        }
    });
    

    推荐而不是自定义 segue 过渡:

    通过创建您自己的动画师来使用自定义动画过渡工作流程,如我在此处的回答中所述:https://stackoverflow.com/a/52396398/7833793

    答案显示了一个用于上/下滑动动画的自定义动画器,但它应该让您清楚地了解如何为交叉淡入淡出做这件事。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-09-17
      • 1970-01-01
      • 2015-06-30
      • 2015-01-06
      • 2019-12-13
      • 1970-01-01
      相关资源
      最近更新 更多