【问题标题】:Black Backgroud while custom transition黑色背景白色自定义过渡
【发布时间】:2019-04-02 16:54:36
【问题描述】:

我想使用自定义过渡来更改视图。它可以工作,但背景是暗/黑色,所以看起来有点奇怪。

我尝试添加

self.window!.backgroundColor = UIColor.white

发给代表,但这并不能解决问题。

这是我的过渡代码

let homeView = self.storyboard?.instantiateViewController(withIdentifier: "ViewController") as! ViewController
        let transition = CATransition()
        transition.duration = 2.3
        transition.type = CATransitionType.reveal
        transition.subtype = CATransitionSubtype.fromLeft
        view.window!.layer.add(transition, forKey: "transition")
        self.dismiss(animated: false, completion: nil)
        present(homeView, animated: false, completion: nil)

【问题讨论】:

    标签: ios swift uitableview caanimation catransition


    【解决方案1】:

    要在过渡期间更改背景颜色,可以是窗口本身:

    UIApplication.shared.keyWindow?.backgroundColor = UIColor.white
    

    根视图控制器:

    if let root = UIApplication.shared.keyWindow?.rootViewController as? YourRootViewController {
        root.view.backgroundColor = UIColor.black
    }
    

    呈现视图控制器或转换的容器视图。

    【讨论】:

    • 将它放在你呈现之前,然后将它改回呈现的完成处理程序中。
    猜你喜欢
    • 2015-01-06
    • 2019-12-13
    • 1970-01-01
    • 2010-11-22
    • 1970-01-01
    • 1970-01-01
    • 2017-04-23
    • 1970-01-01
    • 2020-09-03
    相关资源
    最近更新 更多