【发布时间】:2017-11-10 04:22:53
【问题描述】:
我正在尝试使用段控制器在我的 tableView 和容器视图之间切换,但是当我尝试在它们之间切换时,它只能工作一半。 TableView 出现又消失,但容器视图从不出现。
这是我的代码:
@IBAction func switchAction(_ sender: UISegmentedControl) {
if sender.selectedSegmentIndex == 0 {
profileTableView.isHidden = false
modelsContainerView.isHidden = true
} else {
profileTableView.isHidden = true
modelsContainerView.isHidden = false
}
}
更新
如果我使用此代码,模拟就会起作用。容器视图出现,但它不像 tableview 那样填满屏幕。
@IBAction func switchAction(_ sender: UISegmentedControl) {
if sender.selectedSegmentIndex == 0 {
UIView.animate(withDuration: 0.5, animations: {
self.profileTableView.alpha = 1
self.modelsContainerView.alpha = 0
})
} else {
UIView.animate(withDuration: 0.5, animations: {
self.profileTableView.alpha = 0
self.modelsContainerView.alpha = 1
})
}
}
我可以说它不起作用,因为我已将容器视图的背景颜色设置为粉红色。这就是当我尝试从 TableView(有效)切换到容器视图时的样子:
所有插座似乎都已连接。我的 UI 设置是段控制器后面的绿色视图,下面有一个 tableView 和一个 containerView 在同一个地方。
非常感谢您在高级方面的帮助。
【问题讨论】:
-
你能截取storyboard中的视图层次吗?
-
已上传。 @LoryHuz
-
哪个视图有绿色背景?您的帖子中不清楚
-
而且...您以这种方式使用容器视图是否有原因?通常,您将在视图顶部放置分段控件,然后在其下方放置一个 ContainerView……然后您将在该容器视图内交换表视图和模型视图。
-
没有真正的理由使用堆栈视图...将您的段背景视图限制在顶部,将容器视图限制在段背景的底部和视图的底部。将“包含的视图”约束到容器视图的 4 个侧面。
标签: ios swift xcode uisegmentedcontrol