【问题标题】:How to present ViewController partially over another ViewController and still be able to interact with the bottom one?如何将 ViewController 部分呈现在另一个 ViewController 上,并且仍然能够与底部的 ViewController 交互?
【发布时间】:2019-01-25 03:44:24
【问题描述】:

我现在正在展示一个几乎透明的 ViewController 而不是另一个,但它禁用了与下面的 ViewController 的交互。这是我现在使用的代码:

topController.modalPresentationStyle = UIModalPresentationStyle.overCurrentContext
bottomController.modalPresentationStyle = UIModalPresentationStyle.currentContext
bottomController.present(topController, animated: true, completion: nil)

如何将顶部控制器部分呈现在底部控制器之上,同时仍允许底部控制器与之交互?

【问题讨论】:

  • 添加和动画 uiview 也会很有帮助。
  • @MuhammedAzharudheen 我刚刚这样做了,但是如果不禁用与它的交互,我无法设置顶部 UIViewController 的框架。

标签: ios swift uiviewcontroller presentviewcontroller


【解决方案1】:

如果您想与bottomController 交互,您应该将UIViewController 添加为 ChildViewController:

bottomController.addChildViewController(topController)
bottomController.view.addSubview(topController.view)
//set here frame or constraints for topController.view

如果您想解雇topController,您应该致电:

topController.removeFromParentViewController()
topController.view.removeFromSuperview()

对于动画,您可以使用:

UIView.animate(withDuration duration: TimeInterval, animations: @escaping () -> Void)

【讨论】:

  • 我刚做了这个,但我不知道如何设置顶部 ViewController 的框架,以便它不会禁用顶部的。当我将顶部控制器的框架设置为 CGRect 时,它会成功更改框架,但最终会禁用顶部控制器。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-02-13
  • 1970-01-01
  • 1970-01-01
  • 2021-02-19
  • 1970-01-01
  • 2018-12-27
相关资源
最近更新 更多