使用NSViewController在osx上切换视图控制器

问题描述 投票:2回答:1

我的故事板上有一个加载栏的视图。当我的代码正在运行时,我希望加载栏继续。一旦完成,我想用一个按钮加载另一个视图控制器。

我通过加载一个新的视图控制器尝试了这个,但我没有任何想法动画师是什么。这是我的代码。

我必须为动画师使用什么?我是不是故事板的概念错了?

  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: ???)
}
swift macos viewcontroller nsviewcontroller
1个回答
0
投票

要实现这一点,我们应该有自定义动画师。请阅读苹果指南。

如果要实现为模态窗口,请按照以下链接:

Transitioning between view controller, OS X

这是另一种实现:

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)
© www.soinside.com 2019 - 2024. All rights reserved.