向右滑动即可关闭ViewControlelr,而无需使用Storyboard Swift [英] Swipe Right to Dismiss ViewControlelr without using Storyboard Swift
问题描述
如何在不使用情节提要的情况下关闭任何View Controller?并且我必须使用UINavigationController来实现吗?如果没有,那怎么办?
How to dismiss any View Controller without using Storyboard ? and do I have to use UINavigationController to achieve this ? if not how then ?
推荐答案
关闭视图控制器的方法是在显示的视图控制器上调用dismiss方法.如果您通过调用 self.present(_:animated:)
从父母那里展示了您的子控制器,则可以调用 self.dismiss(animated:)
.如果您使用了NavigationController并调用了 navigationController.push(_:animated:)
,则需要通过 navigationController.popViewController(animated:)
告诉导航控制器关闭方法名称可能不准确,但是您应该可以通过自动完成功能将其弄清楚.
The way to dismiss a view controller is to call a dismiss method on the presenting view controller. If you presented your child controller from a parent by calling self.present(_:animated:)
then you can call self.dismiss(animated:)
. If you used a navigationController and called navigationController.push(_:animated:)
then you need to tell the navigation controller to dismiss with navigationController.popViewController(animated:)
Method names might not be exact, but you should be able to figure it our with autocomplete.
这篇关于向右滑动即可关闭ViewControlelr,而无需使用Storyboard Swift的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!