Rajmund Zawiślak
Rajmund Zawiślak

Reputation: 942

NSPageController bad transition

I have a problem with page controller transition, it looks like this

bad transition

Here is the code of my page controller

class PageController: NSPageController, NSPageControllerDelegate {

    override func viewDidLoad() {
        super.viewDidLoad()

        delegate = self
        arrangedObjects = ["FirstViewController", "SecondViewController"]
    }

    func pageController(_ pageController: NSPageController, identifierFor object: Any) -> String {
        return object as! String
    }

    @IBAction func forward(_ sender: Any) {
        self.navigateForward(self)
    }

    @IBAction func back(_ sender: Any) {
        navigateBack(self)
    }

    func pageController(_ pageController: NSPageController, viewControllerForIdentifier identifier: String) -> NSViewController {
        return storyboard!.instantiateController(withIdentifier: identifier) as! NSViewController
    }

    func pageControllerDidEndLiveTransition(_ pageController: NSPageController) {
        pageController.completeTransition()
    }
}

Why does it look like this and what can I do to achieve normal transition?

Upvotes: 0

Views: 434

Answers (1)

Abizern
Abizern

Reputation: 150665

When you push a new page the original page is still in the view hierarchy because it has to be shown while the new page animates into view. Once the new view completely covers the original view it is removed. Because you have a transparent background on the second view, you can still see the buttons underneath.

When you push the new page off the screen, the view underneath is added to the hierarchy so you can see it as the top view animates away. Because the top view is transparent, the buttons appear before the view animates.

If you make the view opaque instead of transparent, the view underneath cannot be seen through the transparent background, so it works as you expect.

Upvotes: 3

Related Questions