当我尝试呈现先前添加为子控制器的视图控制器时,出现Unbalanced calls to begin/end appearance transitions错误,如何解决此问题?

开始/结束外观转换的 call 不平衡

class VideoViewController: UIViewController {

}


class BigPlayerVC: UIViewController {
    let videoVC = VideoViewController()

    override func viewDidLoad() {
        super.viewDidLoad()
        addChild(videoVC)
        view.addSubview(videoVC.view)
        videoVC.view.translatesAutoresizingMaskIntoConstraints = false
    //  view.constrainViewEqual(videoReactController.playerView, top: 0, bottom: 0, left: 0, righta: 0)
        videoVC.didMove(toParent: self)
    }

    @objc func onBTNClick() {
        videoVC.willMove(toParent: nil)
        videoVC.view.removeFromSuperview()
        videoVC.view.translatesAutoresizingMaskIntoConstraints = true
        videoVC.removeFromParent()
        self.present(videoVC, animated: false, completion: nil)
    }
}

最佳答案

我有一个临时的解决方案:只需在DispatchBlock中延迟移动present方法
如下所示:

DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 0.1) {
    self.present(videoVC, animated: false, completion: nil)
}

关于ios - 尝试呈现ViewController时对开始/结束外观过渡的不平衡调用,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/55967189/

10-11 20:26