如何在swift中使用模态视图?

向Mail(在首选项)中添加一个帐户时,您将获得一个模式视图,如下所示: 示例图片,来源:kb.xcentric.com/images/ipad12.jpg

我的问题是,如何复制这个编程? 换句话说,如何在展示视图上显示模态UIView?

这是我有:

import UIKit class ViewController: UIViewController { @IBAction func addCard(sender: AnyObject) { var addContact : secondViewController = secondViewController() self.modalTransitionStyle = UIModalTransitionStyle.FlipHorizontal self.modalPresentationStyle = .CurrentContext // Display on top of current UIView self.presentViewController(addContact, animated: true, completion: nil) } //Code goes on to do other unrelated things 

另外,我做了以下几点:

  1. 在界面构build器中创build了视图控制器。
  2. 将BarButtonItem的“添加联系人”连接到视图控制器,通过按住Ctrl键并拖动到要显示的视图的视图控制器,然后在下拉列表中select“模式”。
  3. 将提供的ViewController的Class和StoryBoard UI设置为secondViewController。

预期的行为是,当UIBarButton“添加联系人”(它成功地触发了上述代码中的@IBAction func addCard(sender: AnyObject) )时,secondViewController被显示为主视图上方的模式视图。

当我运行上面的代码,我得到错误"Use of undeclared type secondViewController"

我究竟做错了什么?

注:这是一个问题 ,我问了一个类似的,但稍有不同的问题。 我检查了元 ,我认为这是确定的 – 我不想在原来的问题上使答案失效,因为这是稍微不同的问题。 另外,如果有帮助的话,我发现了一些类似的问题 – 在obj中。我该如何快速地做到这一点?

尝试这个 :)

 @IBAction func addCard(sender: AnyObject) { self.modalTransitionStyle = UIModalTransitionStyle.coverVertical // Cover Vertical is necessary for CurrentContext self.modalPresentationStyle = .currentContext // Display on top of current UIView self.present(secondViewController(), animated: true, completion: nil) }