'Adjust embedded view controllers size in a tab bar view controller
I have a tab bar view controller subclass which has tabs and also has a view above those tabs that it keeps persistent between switching tabs. I'd like to resize the view controllers that are embedded within the tab bar view controller to account for both the tab bar and this view. I did so by adjusting my view with the following code:
strongSelf.viewControllers?.first?.forEach({ vc in
vc.view.snp.makeConstraints { make in
make.bottom.equalTo(strongSelf.promoView?.snp.top ?? strongSelf.view.snp.bottom)
}
})
Where the promoView is the view that is above my tab bar view. This works fine in the one tab case where there is no tab bar and resizes properly to adjust for the promo view, however when I have multiple tabs I get an exception which states
Terminating app due to uncaught exception 'NSGenericException', reason: 'Unable to activate constraint with anchors <NSLayoutYAxisAnchor:0x60000380c100 "UILayoutContainerView:0x7fa265822870.bottom"> and <NSLayoutYAxisAnchor:0x60000387ff40 "SharedUI.View:0x7fa2653a5350.top"> because they have no common ancestor. Does the constraint or its anchors reference items in different view hierarchies? That's illegal.'
Is there an issue with adjusting the embedded view controllers in the tab view controller if the tab bar is present? If so, how do I get around this so I can resize it with both the promo view and tab bar?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
