I scratched my head over this problem. This seems to be related to how the tabBar is initialized and added to view the hierarchy. I also tried solutions like calling invalidateIntrinsicContentSize , setting a frame, and also bottomInsets inside a subclass of UITabBar. They seem to work, but temporarily, and they break some other script or regress the tab bar, causing some ambiguous layout problem. When I debugged the problem, I tried to assign height limits to UITabBar and centerYAnchor, however, no problem was fixed. I realized that the tabBar height was correct before and after reproducing the problem, which made me think that the problem was in the subtitles. I used the code below to successfully solve this problem without regressing any other scenario.
- (void) viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator { [super viewWillTransitionToSize:size withTransitionCoordinator:coordinator]; if (DEVICE_IS_IPHONEX()) { [coordinator animateAlongsideTransition:^(id<UIViewControllerTransitionCoordinatorContext> _Nonnull context) { for (UIView *view in self.tabBar.subviews) { if ([NSStringFromClass(view.class) containsString:@"UITabBarButton"]) { if (@available (iOS 11, *)) { [view.bottomAnchor constraintEqualToAnchor:view.superview.safeAreaLayoutGuide.bottomAnchor].active = YES; } } } } completion:^(id<UIViewControllerTransitionCoordinatorContext> _Nonnull context) { [self.tabBar layoutSubviews]; }]; } }
Assumptions: I only do this for the iPhone X, as it is not currently playing on any other device. Based on the assumption that Apple will not change the class name UITabBarButton in future releases of iOS. We do this on UITabBarButton only when it means that if apples add more internal routines to UITabBar, we may need to change the code to adapt to this.
Please let me know if this works, suggestions and improvements will be open!
To do this, it should be easy to create a quick equivalent.
Rushabh Nov 16 '17 at 1:21 2017-11-16 01:21
source share