2

I have a view with a loading bar on my story board. While my code is operating i want the loading bar to proceed. Once it is finished i want to load another view controller with a button.

I tried this by loading a new view Controller but i don't have any Idea what the animator is. Here is my code.

What do i have to use for animator? I'm i getting the concept of the storyboard wrong?

  override func viewDidAppear() {
    super.viewDidAppear()
    var deadlineTime = DispatchTime.now() + .seconds(1)
    progressView.style = NSProgressIndicatorStyle(rawValue: 0)!;
    progressView.startAnimation(self);
    DispatchQueue.main.asyncAfter(deadline: deadlineTime) {
        self.progressView.increment(by: 5)
        deadlineTime = DispatchTime.now() + .seconds(1)
        DispatchQueue.main.asyncAfter(deadline: deadlineTime) {
            deadlineTime = DispatchTime.now() + .seconds(1)
            self.progressView.increment(by: 10)
            DispatchQueue.main.asyncAfter(deadline: deadlineTime) {
                self.progressView.increment(by: 20)
                self.progressView.stopAnimation(self)
                //self.performSegue(withIdentifier: "bla", sender: self)
                self.switchScreen()
            }
        }
    }
}


func switchScreen(){
    let main = NSStoryboard(name: "Main", bundle: Bundle.main)
    let vc = self.storyboard?.instantiateController(withIdentifier: "finished") as! NSViewController
    self.presentViewController(vc, animator: ???)
}
Silve2611
  • 2,198
  • 2
  • 34
  • 55

1 Answers1

0

To implement this, we should have custom animator. Please read the apple guidelines.

Follow the below link if you want to implement as modal window:

Transitioning between view controller, OS X

This is another implementation :

Animate custom presentation of ViewController in OS X Yosemite

/* Presents the viewController with a specific animator that handles both the presentation and dismissal of the viewController. The animator is held onto until dismissViewController: is called. This is the fundamental primitive for displaying view controllers that block interaction in some way. The method will assert if animator is nil. In general, you will not directly call this method unless you have a custom animator. Instead, you will use one of the standard cover methods that provide the animator: 
[NSViewController presentViewControllerAsSheet:], [NSViewController presentViewControllerAsModalWindow:], [NSViewController presentViewController:asPopoverRelativeToRect:...]
    */    
 @available(OSX 10.10, *)
    open func present(_ viewController: NSViewController, animator: NSViewControllerPresentationAnimator)