ios - 自定义过渡时的黑色背景

标签 ios swift uitableview caanimation catransition

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

我尝试添加

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)

最佳答案

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

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

Root View Controller :

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

呈现 View Controller 或转换的容器 View 。

关于ios - 自定义过渡时的黑色背景,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55479946/

相关文章:

ios - viewForHeaderInSection 对齐错误(Swift 3)

iphone - UITableViewCell,具有动态高度的 UITextView

ios - 调用 reloadRowsAtIndexPaths 方法时动态单元格高度导致反弹效果

ios - 根据其框架大小设置 UILabel 字体大小?

ios - @IBOutlet 默认情况下在 iOS 中应该是私有(private)的还是内部的?

ios - 以编程方式在场景之间进行转换的问题

ios - 如何只允许一个单元格可点击

ios - UIView 中的 UIButton 在另外两个 UIView 后面对上面的 View 的触摸使用react

ios - SpriteKit : Why containsPoint of SKNode returns false

objective-c - UITableView - 在不阻塞主线程的情况下从 NSBundle 加载大型 UIImages