Ios 如何在swift中使用模态视图?
将帐户添加到邮件时(在“首选项”中),您会看到一个模式视图,如下所示: 我的问题是,我如何以编程的方式复制它?换句话说,如何在演示视图上显示模态UIView 以下是我所拥有的:Ios 如何在swift中使用模态视图?,ios,swift,interface-builder,modalviewcontroller,Ios,Swift,Interface Builder,Modalviewcontroller,将帐户添加到邮件时(在“首选项”中),您会看到一个模式视图,如下所示: 我的问题是,我如何以编程的方式复制它?换句话说,如何在演示视图上显示模态UIView 以下是我所拥有的: import UIKit class ViewController: UIViewController { @IBAction func addCard(sender: AnyObject) { var addContact : secondViewController = secondViewCon
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
此外,我还做了以下工作:
@IBAction func addCard(发送者:AnyObject)
)时,secondViewController在主视图上方显示为模式视图
当我运行上面的代码时,会出现错误“使用未声明的类型secondViewController”
我做错了什么
注意:这是我的一个重新提问,我问了一个类似但略有不同的问题。我检查了一下,我觉得没关系——我不想否定原来问题的答案,因为这是在问一些稍微不同的问题。另外,如果有帮助,我在obj C中发现了一些问题。我如何在swift中做到这一点?试试这个:)
如果您计划使用iOS8,可以看一看WWDC 2014视频“会话228-演示控制器内部视图”,该视频涉及UIPresentationController类。什么是secondViewController?您是否定义了该类?@dr我将secondViewController设置为要显示的视图控制器的interface builder(在“set class”字段中)中的类。还有什么我需要做的吗?你能粘贴secondViewController文件的代码吗?@dr好极了,我没有secondViewController文件-我想我可以用上面的(不正确的)代码从主视图控制器控制显示的视图。对于显示的视图,是否需要第二个viewcontroller?
@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)
}