Reputation: 23
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
}
Upvotes: 0
Views: 237
Reputation: 52
override func layoutSubviews() {
super.layoutSubviews()
DispatchQueue.main.async {
if self.Bzcardview_.isHidden{
self.containerviewHeighContraint.constant = vc.view.height
self.containerviewHeighContraint.constant = self.BzcardView.view.height
}else{
self.containerviewHeighContraint.constant = InformationTabView.InnerviewHeightContraint.constant + 50
self.containerviewHeighContraint.constant = InformationTabView.InnerviewHeightContraint.constant
}
}
}
Upvotes: 0