Unbalanced calls to begin/end appearance transitions for

前端 未结 25 1109
陌清茗
陌清茗 2020-12-02 06:31

I have this problem when I simulate my app, its not an error or a warning but it appears in my console, has anyone ever experienced this before?

25条回答
  •  春和景丽
    2020-12-02 06:58

    I had a similar problem that involved rewinding modal dialogs. Posted the solution here...

    https://stackoverflow.com/a/38795258/324479

    [Problem]

    Nav Controller -> VC1 -Push--> VC2 -PopOver or Modal Segue--> VC3.

    VC3 is unwinding back to VC1.

    When the Segue from VC2 to VC3 is PopOver and Modal, the unwind ends in a warning: Unbalanced calls to begin/end appearance transitions for UIViewController"

    If the Segue from VC to VC is push, the warning is gone.

    [Solution]

    It would be great if the unwind logic would take care of this. Maybe it's a bug, maybe not. Either way, the solution is to make VC2 (The controller that has the popup) the target of the rewind, then wait for it to finish appearing before popping up the nav controller. That ensures the rewind (reverse popup) animation has enough time to finish before moving further back. Even with the animations off, it still has to wait or else you get the error.

    Your code for VC2 should be as follows. (Swift)

    class VC2: UIViewController {
        private var unwind = false
        @IBAction func unwindToVC1(segue:UIStoryboardSegue) {
            unwind = true
        }
    
        override func viewWillAppear(animated: Bool) {
            super.viewWillAppear(animated)
    
            if unwind {
                self.navigationController?.popViewControllerAnimated(false)
            }
        }
    }
    

提交回复
热议问题