我的故事板上有一个加载栏的视图。当我的代码正在运行时,我希望加载栏继续。一旦完成,我想用一个按钮加载另一个视图控制器。
我通过加载一个新的视图控制器尝试了这个,但我不知道动画师是什么。这是我的代码。
动画师必须使用什么?我是否弄错了故事板的概念?
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: ???)
}
答案 0 :(得分: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)