gpt4 book ai didi

swift - 使用 NSViewController 在 osx 上切换 View Controller

转载 作者:搜寻专家 更新时间:2023-11-01 05:35:42 26 4
gpt4 key购买 nike

我的 Storyboard上有一个带有加载栏的 View 。当我的代码运行时,我希望加载栏继续。一旦完成,我想用一个按钮加载另一个 View Controller 。

我通过加载一个新的 View Controller 来尝试这个,但我不知道动画师是什么。这是我的代码。

我必须为动画师使用什么?我弄错了 Storyboard 的概念吗?

  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: ???)
}

最佳答案

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

如果您想实现为模态窗口,请点击以下链接:

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)

关于swift - 使用 NSViewController 在 osx 上切换 View Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41093819/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com