向Mail添加帐户(在首选项中)时,您会看到一个模态视图,如下所示:
我的问题是,如何以编程方式复制此内容?换句话说,如何在呈现视图上显示模态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
另外,我做了以下事情:
预期的行为是,当按下UIBarButton“Add Contact”(在上面的代码中成功触发@IBAction func addCard(sender: AnyObject)
)时,secondViewController将显示为主视图上方的模态视图。
当我运行上面的代码时,我收到错误"Use of undeclared type secondViewController"
我做错了什么?
注意:这是对an earlier question的重新询问,其中我问了一个类似但略有不同的问题。我检查了meta,我认为没关系 - 我不想让原始问题的答案无效,因为这是在问一些稍微不同的东西。另外,如果它有帮助,我发现了一些similar个问题 - 在obj C.我如何在swift中做到这一点?
答案 0 :(得分:8)
试试这个:)
@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)
}