将帐户添加到“邮件”(首选项)时,您将获得一个模态视图,如下所示:

我的问题是,如何以编程方式复制此内容?换句话说,如何在呈现 View 上显示模式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

此外,我还完成了以下操作:
  • 在“界面”构建器中创建了“ View Controller ”。
  • 通过按住Control键单击并拖动到我要显示的 View 的ViewController,然后在下拉列表中选择“modal”,将BarButtonItem“添加联系人”连接到ViewController。
  • 将提供的Viewcontroller的Class和StoryBoard UI设置为secondViewController。

  • 预期的行为是,当按下UIBarButton“添加联系人”(成功触发以上代码中的@IBAction func addCard(sender: AnyObject))时,secondViewController在主 View 上方显示为模态视图。

    当我运行上面的代码时,出现错误"Use of undeclared type secondViewController"
    我究竟做错了什么?

    注意:这是对an earlier question的重新询问,其中我问了一个类似但略有不同的问题。我检查了meta,我认为还可以-我不想使原始问题的答案无效,因为这是在问一些稍有不同的问题。另外,如果有帮助,我在obj C中发现了一些similar问题。如何快速完成此操作?

    最佳答案

    试试这个 :)

    @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)
    }
    

    关于ios - 如何快速使用模态视图?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/25223607/

    10-12 14:32
    查看更多