简体   繁体   English

如何从包含在一个 VC 中的一个 VC 转换为将包含在与另一个相同的 VC 中的新 VC?

[英]How to transition from one VC contained in one VC, to a new VC which will be contained in the same VC as the other?

When the app launches you begin on the ViewController (the one in the middle).当应用程序启动时,您开始使用 ViewController(中间的那个)。 From there I add the VC on the right.从那里我在右边添加了 VC。 When a user taps a button which is on this VC I want that view to go away (which I currently accomplish by just changing its frame to 900) and in its place comes the VC on the Left.当用户点击此 VC 上的按钮时,我希望该视图消失(我目前只需将其框架更改为 900 即可完成),取而代之的是左侧的 VC。

All the things I have tried failed given that I am so unclear on how to do this.鉴于我不清楚如何做到这一点,我尝试过的所有事情都失败了。

How do I make this kind of functionality work?我如何使这种功能发挥作用?

You can do this by:您可以通过以下方式执行此操作:

        if let ViewController2 = segue.destination as? ViewController2 {        
            //here...   
        } else if let viewcontroller = segue.destination as? ViewController1 {
            //here..
        }

Assuming you have reference to the container view you can hide and unhide Views but the RightViewController on the right must communicate to the main middle MiddleViewController假设您引用了容器视图,您可以隐藏和取消隐藏视图,但右侧的RightViewController必须与主要的中间MiddleViewController通信

Here you can use Protocols to communicate between the two, have a look into https://medium.com/@nimjea/delegation-pattern-in-swift-4-2-f6aca61f4bf5 for more details.在这里,您可以使用Protocols在两者之间进行通信,查看https://medium.com/@nimjea/delegation-pattern-in-swift-4-2-f6aca61f4bf5了解更多详细信息。

When the RightViewController tells/delegates the MiddleViewController that the button is tappedRightViewController告诉/委托MiddleViewController按钮被点击时

you can just你可以

self.rightContainerView.isHidden = true
self.leftContainerView.isHidden = left

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM