gpt4 book ai didi

ios - 使用 Swift 4 关闭 iOS 中的所有模式

转载 作者:可可西里 更新时间:2023-11-01 01:56:07 25 4
gpt4 key购买 nike

我正在尝试实现类似于 iOS 版 Netflix 应用程序的导航。当您单击电影时,会弹出一个带有关闭按钮的模态窗口。如果在这部电影中我选择看另一部电影,则会弹出第二个模式,除了关闭按钮外,还会出现一个后退按钮。我可以使用后退按钮逐一关闭,使用关闭按钮返回基本屏幕。

我可以使用

关闭单个 View
dismiss(animated: true, completion: nil)

但是我怎样才能返回到基本屏幕一次关闭所有模式?另外,模式是要走的路吗?我选择这个是因为我不希望导航栏位于顶部。

我在 Xcode 10 中使用 Swift 4.2。

最佳答案

您关闭 ViewController 的方式不正确。呈现 View Controller 负责关闭 View Controller 。理想情况下,您必须在呈现的 ViewController 中实现一个协议(protocol),并且从“呈现”ViewController 而不是“呈现”ViewController 中关闭您的模态。

你的方法仍然有效的原因是,当 ViewController 调用 self.dimiss 时,如果没有什么可以关闭,UIKit 会将它委托(delegate)回其父级。如果您实现这种正确的方式,一旦您 dismiss ,您呈现的 viewcontroller 将 dismiss ,因此所有呈现的 viewcontroller 将被 dismissed 而不是最后一个。

From Apple Docs:

The presenting view controller is responsible for dismissing the view controller it presented. If you call this method on the presented view controller itself, UIKit asks the presenting view controller to handle the dismissal.

If you present several view controllers in succession, thus building a stack of presented view controllers, calling this method on a view controller lower in the stack dismisses its immediate child view controller and all view controllers above that child on the stack. When this happens, only the top-most view is dismissed in an animated fashion; any intermediate view controllers are simply removed from the stack. The top-most view is dismissed using its modal transition style, which may differ from the styles used by other view controllers lower in the stack.

If you want to retain a reference to the view controller's presented view controller, get the value in the presentedViewController property before calling this method.

The completion handler is called after the viewDidDisappear(_:) method is called on the presented view controller.

关于ios - 使用 Swift 4 关闭 iOS 中的所有模式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53320448/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com