无法将 UISegmentedControl 与三个选项卡和 ContainerView 一起使用

Not able to use UISegmentedControl with three tabs and ContainerView

我用 Xcode 和 Swift 制作了一个 iOS 应用程序。我想将 UISegmentedControl 与三个选项卡一起使用。通过这些选项卡,我可以在三个 ContainerView 之间切换。

我必须在 alpha 字段中输入哪些数字? 0、1 和 2?因为当我设置 2 时,它总是恢复为 1。这是为什么呢?我该怎么做?

这是我用来将选项卡与 ContainerView 连接的代码:

    @IBAction func switchSegmentedControll(sender: UISegmentedControl) {
        if sender.selectedSegmentIndex == 0 {
            UIView.animateWithDuration(0.5, animations: {
                self.segmentedControllFirst.alpha = 1
                self.segmentedControllSecond.alpha = 0
//                self.segmentedControllThird.alpha = 0
            })
        } else {
            UIView.animateWithDuration(0.5, animations: {
                self.segmentedControllFirst.alpha = 0
                self.segmentedControllSecond.alpha = 1
//                self.segmentedControllThird.alpha = 1
            })
        }
    }

如果您想要三个选项卡,请将 Segments 字段设置为“3”,如下面的屏幕截图所示:

alpha 值介于 0 到 1 之间,用于可见性。您不能将 alpha 值设置为大于 1

我想我刚刚找到了解决方案。这是我自己的误会。我不知道 Alpha 是什么以及我使用的代码是如何工作的。

这是工作代码:

@IBAction func switchSegmentedControll(sender: UISegmentedControl) {
    if sender.selectedSegmentIndex == 0 {
        UIView.animateWithDuration(0.5, animations: {
            self.segmentedControllFirst.alpha = 1
            self.segmentedControllSecond.alpha = 0
            self.segmentedControllThird.alpha = 0
        })
    } else if sender.selectedSegmentIndex == 1 {
        UIView.animateWithDuration(0.5, animations: {
            self.segmentedControllFirst.alpha = 0
            self.segmentedControllSecond.alpha = 1
            self.segmentedControllThird.alpha = 0
        })
    } else {
        UIView.animateWithDuration(0.5, animations: {
            self.segmentedControllFirst.alpha = 0
            self.segmentedControllSecond.alpha = 0
            self.segmentedControllThird.alpha = 1
        })
    }
}