2016-03-28 138 views
0

通常,我們可以通過具有不同種類的NSStoryboardSeque(像Present,Show,Sheet等)來顯示下一個視圖控制器,但是,我們如何通過編程實現同樣的功能?Cocoa - 以編程方式呈現NSViewController

與UIViewController進行比較,模態地呈現視圖控制器presentViewController:animated:。 NSViewController有沒有同樣的方法?

在此先感謝。

回答

1

我使用的兩種不同表現類型有:

func presentViewControllerAsModalWindow(_ viewController: NSViewController) 
func presentViewControllerAsSheet(_ viewController: NSViewController) 

做一些調查研究的另一種方式使用後做到:

func presentViewController(_ viewController: NSViewController, animator: NSViewControllerPresentationAnimator) 

,吃一個自定義演示動畫。在這裏,你可以自由地做你喜歡:)

+0

你用NSViewControllerPresentationAnimator做了什麼?你如何打電話或創建它? – Silve2611

0

1.創建一個NSViewController實例與故事板標識符

let theTESTVCor = self.storyboard?.instantiateController(withIdentifier: "TESTVCor") as! NSViewController 

2.Present在通過電流NSViewController

theNSViewController.presentViewControllerAsModalWindow(theTESTVCor) 

⚠️不要忘記設置故事板中的NSViewController的標識符

相關問題