roc*_*101 5 interface-builder modalviewcontroller ios swift
将帐户添加到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
Run Code Online (Sandbox Code Playgroud)
另外,我做了以下事情:
预期的行为是,当按下UIBarButton"Add Contact"(@IBAction func addCard(sender: AnyObject)
在上面的代码中成功触发 )时,secondViewController将呈现为主视图上方的模态视图.
当我运行上面的代码时,我收到错误 "Use of undeclared type secondViewController"
我究竟做错了什么?
注意:这是对早期问题的重新提问,其中我问了一个类似但略有不同的问题.我检查了meta,我认为它没关系 - 我不想让原始问题的答案无效,因为这是在问一些稍微不同的东西.另外,如果它有帮助,我发现了一些类似的问题 - 在obj C.我如何在swift中做到这一点?
试试这个 :)
@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)
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
12666 次 |
最近记录: |