在分段控件中重置子视图

时间:2017-12-05 23:58:50

标签: ios swift segmentedcontrol

我使用分段控件来旋转内容,但是当我滚动到子视图的末尾并切换到另一个分段时,新分段显示与前一分段大致位于相同的位置(即,如果我滚动到段A和开关段的底部,段B也位于滚动的底部)。如何重置每个细分,以便每次更改细分时它都位于顶部?

示例代码:

class AboutUsViewController: UIViewController {        
    @IBOutlet weak var welcomeContainer: UIView!
    var views: [UIView]!

    override func viewDidLoad() {
        super.viewDidLoad()

        views = [UIView]()
        views.append(ViewController1().view)
        views.append(ViewController2().view)
        views.append(ViewController3().view)
        views.append(ViewController4().view)

        for view in views {
            welcomeContainer.addSubview(view)
        }

        welcomeContainer.bringSubview(toFront: views[0])   
    }

    @IBAction func swichViewAction(_ sender: UISegmentedControl) {
        self.welcomeContainer.bringSubview(toFront: views[sender.selectedSegmentIndex])
    }
}

0 个答案:

没有答案