Swift3 从viewController快速更改容器

Swift3 从viewController快速更改容器,swift3,containers,segue,Swift3,Containers,Segue,在主viewController中,我将容器视图和2个按钮放置在其下方。我只想通过这些按钮更改容器部分。默认显示container1,当按下按钮2时,container部件切换到container2。我该怎么做?谢谢,基于这篇文章,我制作了我的版本,它运行正常。 在他的文章中,他在interface builder中将container2的alpha值设置为0。然而,这对我不起作用。因此,我在interface builder 1中为这两个容器设置了alpha值,如下屏幕截图所示 这是主vie

在主viewController中,我将容器视图和2个按钮放置在其下方。我只想通过这些按钮更改容器部分。默认显示container1,当按下按钮2时,container部件切换到container2。我该怎么做?谢谢,

基于这篇文章,我制作了我的版本,它运行正常。

在他的文章中,他在interface builder中将container2的alpha值设置为0。然而,这对我不起作用。因此,我在interface builder 1中为这两个容器设置了alpha值,如下屏幕截图所示

这是主viewController的代码

import UIKit

class ViewController: UIViewController {


    @IBOutlet weak var containerViewA: UIView!

    @IBOutlet weak var containerViewB: UIView!


    override func viewDidLoad() {
        super.viewDidLoad()

        // below sets the container1 as default
        self.containerViewA.alpha = 1
        self.containerViewB.alpha = 0

    }


    @IBAction func button1(_ sender: Any) {

        self.containerViewA.alpha = 1
        self.containerViewB.alpha = 0

    }

    @IBAction func button2(_ sender: Any) {

        self.containerViewA.alpha = 0
        self.containerViewB.alpha = 1

    }

}