【问题标题】:Make a swipe from left edge to dismiss UIViewController从左边缘滑动以关闭 UIViewController
【发布时间】:2018-12-12 03:17:46
【问题描述】:

例如,我有两个 UIViewController(我将分别称为 A 和 B)

在A中,当我点击一个按钮时,我会用代码显示B:

let storyboard = UIStoryboard(name: "Main", bundle: nil)
let viewController = storyboard.instantiateViewController(withIdentifier:"BController") as! BController
present(viewController, animated: true)

我没有在 Storyboard 文件中使用导航 ViewController。 那么,在B中应用时,我从左边缘滑动屏幕,B会关闭,是否有任何解决方案。

你可以想象我在这张图片中想要什么

【问题讨论】:

  • “我的项目中没有使用导航控制器!!!” 为什么!!!
  • @RakeshaShastri 因为我的项目非常复杂,而且现在很大,有很多故事板和 ViewController,我无法更改此结构
  • 你将如何改变结构?您需要做的就是添加一个导航控制器。
  • @RakeshaShastri 我做到了,这完全是我想要的,谢谢。更多细节在我下面的回答中

标签: ios swift


【解决方案1】:

将控制器添加到NavigationController 我是通过代码实现的:

let storyboard = UIStoryboard(name: "Main", bundle: nil)
let viewController = storyboard.instantiateViewController(withIdentifier:"AController")
 let navigationController = UINavigationController(rootViewController: viewController)
 navigationController.isNavigationBarHidden = true
 self.present(navigationController, animated: true)

然后从 A

self.navigationController?.pushViewController(bController, animated: true)

【讨论】:

    【解决方案2】:

    您需要编写一个交互式自定义过渡动画。这样做很复杂,但在教程和示例中都有很好的记录。

    【讨论】:

    • 例如,在这里查看我的答案:stackoverflow.com/a/51580236/341994 这是一个标签栏控制器,而不是显示的控制器,但机制完全相同。
    • 谢谢,调查需要更多时间。我注意到了,稍后会阅读。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-02-17
    • 2013-12-16
    • 1970-01-01
    • 1970-01-01
    • 2016-05-23
    • 2018-04-30
    • 1970-01-01
    相关资源
    最近更新 更多