滚动在子视图中不起作用 - swift(iOS)
我在containerview中添加了子视图,containerview高度会随着子视图高度的变化而更新。当Bzcardview显示时,它将隐藏containerview,当containerview显示时,它将隐藏Bzcardview。 Bazcardview和containerview都有相同的约束。
func UpdateSubviewHeight() {
if segmentHeaderView.selectedSegmentIndex == 0
{
self.containerviewHeighContraint.constant = InformationTabView.InnerviewHeightContraint.constant + 50
}
else {
self.containerviewHeighContraint.constant = self.BzcardView.view.height
}
self.view.layoutIfNeeded()
}
private func addChildViewController(vc: UIViewController) {
self.Containerview.addSubview(vc.view)
if vc == FirstTabView
{
self.containerviewHeighContraint.constant = InformationTabView.InnerviewHeightContraint.constant
}
else {
self.containerviewHeighContraint.constant = vc.view.height
}
self.view.layoutIfNeeded()
activateRequiredConstraints(for: vc.view)
vc.didMove(toParent: self)
}
private func activateRequiredConstraints(for childView: UIView) {
childView.translatesAutoresizingMaskIntoConstraints = false
NSLayoutConstraint.activate([
childView.leadingAnchor.constraint(equalTo: Containerview.leadingAnchor, constant: 0),
childView.trailingAnchor.constraint(equalTo: Containerview.trailingAnchor, constant: 0),
childView.topAnchor.constraint(equalTo: Containerview.topAnchor, constant: 0),
childView.bottomAnchor.constraint(equalTo: Containerview.bottomAnchor, constant: 0),
childView.heightAnchor.constraint(equalTo: Containerview.heightAnchor, constant: 0)
])
}
当选项卡更改时,它只执行隐藏和显示操作。
if segmentedControl.selectedSegmentIndex == 0
{
self.InformationTabView.view.isHidden = false
self.ExposuresView.view.isHidden = true
self.Bzcardview_.isHidden = true
self.scrollview.isScrollEnabled = true
self.Bzcardview_.isHidden = true
self.Bzcardview_.isUserInteractionEnabled = false
}
else if segmentedControl.selectedSegmentIndex == 1
{
self.InformationTabView.view.isHidden = true
self.Bzcardview_.isHidden = false
self.Bzcardview_.isUserInteractionEnabled = true
self.ExposuresView.view.isHidden = true
self.scrollview.isScrollEnabled = false
}
I have added child view inside the containerview, containerview height will update as subview height changed.when Bzcardview display,it will hide containerview and when containerview display it will hide Bzcardview. Bazcardview and containerview both having same contraint.
func UpdateSubviewHeight() {
if segmentHeaderView.selectedSegmentIndex == 0
{
self.containerviewHeighContraint.constant = InformationTabView.InnerviewHeightContraint.constant + 50
}
else {
self.containerviewHeighContraint.constant = self.BzcardView.view.height
}
self.view.layoutIfNeeded()
}
private func addChildViewController(vc: UIViewController) {
self.Containerview.addSubview(vc.view)
if vc == FirstTabView
{
self.containerviewHeighContraint.constant = InformationTabView.InnerviewHeightContraint.constant
}
else {
self.containerviewHeighContraint.constant = vc.view.height
}
self.view.layoutIfNeeded()
activateRequiredConstraints(for: vc.view)
vc.didMove(toParent: self)
}
private func activateRequiredConstraints(for childView: UIView) {
childView.translatesAutoresizingMaskIntoConstraints = false
NSLayoutConstraint.activate([
childView.leadingAnchor.constraint(equalTo: Containerview.leadingAnchor, constant: 0),
childView.trailingAnchor.constraint(equalTo: Containerview.trailingAnchor, constant: 0),
childView.topAnchor.constraint(equalTo: Containerview.topAnchor, constant: 0),
childView.bottomAnchor.constraint(equalTo: Containerview.bottomAnchor, constant: 0),
childView.heightAnchor.constraint(equalTo: Containerview.heightAnchor, constant: 0)
])
}
When tab changed it just perform hide and show action.
if segmentedControl.selectedSegmentIndex == 0
{
self.InformationTabView.view.isHidden = false
self.ExposuresView.view.isHidden = true
self.Bzcardview_.isHidden = true
self.scrollview.isScrollEnabled = true
self.Bzcardview_.isHidden = true
self.Bzcardview_.isUserInteractionEnabled = false
}
else if segmentedControl.selectedSegmentIndex == 1
{
self.InformationTabView.view.isHidden = true
self.Bzcardview_.isHidden = false
self.Bzcardview_.isUserInteractionEnabled = true
self.ExposuresView.view.isHidden = true
self.scrollview.isScrollEnabled = false
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)