按下按钮时,我希望使用模态转换样式CoverVertical
在两个视图控制器之间进行切换,然后将其关闭。有关于如何在目标C中执行此操作的信息,但在Swift中找不到任何好的信息。到目前为止我已经做到了这一点,但我不认为这是正确的:
@IBAction func insertStatus(sender: UIButton) {
var StatusVC: StatusViewController = StatusViewController()
var modalStyle: UIModalTransitionStyle = UIModalTransitionStyle.CoverVertical
StatusVC.modalTransitionStyle = modalStyle
self.presentViewController(StatusVC, animated: true, completion: nil)
}
我正在使用的解雇也不起作用:
@IBAction func statusSaved(sender: UIBarButtonItem) {
self.dismissViewControllerAnimated(false, completion: { () -> Void in
let usersVC: UsersViewController = self.storyboard?.instantiateViewControllerWithIdentifier("UsersViewController") as UsersViewController
})
}
答案 0 :(得分:28)
Swift 4:
present(UIViewController(), animated: true, completion: nil)
dismiss(animated: true, completion: nil)
Swift 2.2:
self.presentViewController(true, completion: nil)
隐藏/取消视图控制器:
self.dismissViewControllerAnimated(true, completion: nil)
答案 1 :(得分:8)
在Swift 3.0中解除视图控制器
self.dismiss(animated: true, completion: {})
答案 2 :(得分:0)
您可以使用presentViewController:animated:completion:
中的dismissViewControllerAnimated:completion:
和UIViewController
方法。请参阅文档here
答案 3 :(得分:0)
非常简单:
使用swift 3.0解除模态视图: 使用如下所示的解雇Api:
> @IBAction func dismissClick(_ sender: Any) {
> dismiss(animated: true, completion: nil)
>
> }
目前:
> @IBAction func dismissClick(_ sender: Any) {
> present(UIViewController(), animated: true, completion: nil)
>
> }
有关详细信息,请访问:
答案 4 :(得分:0)
在Swift 4中关闭视图控制器:
dismiss(animated: true, completion: nil)