Why Tabbar's Push Animation Page Moves Up in iPhone X

I am creating a Demo application, use hidesBottomBarWhenPushed hide Tabbar in Push Animation.

Page Relationship

But, when do I push Tabbar Tabbar up !? like this: Tabbar move up

+31
ios ios11 iphone-x
Sep 15 '17 at 6:19 06:19
source share
7 answers

The answer provided by VoidLess fixes TabBar problems only partially. It fixes problems with the layouts on the tab, but if you use a viewcontroller that hides the tab, the tab does not display correctly during animation (for playback, it is best 2 have 2 segues - one modal and one click. If you alternate segues, you can see the tab being inappropriate). See the code below that fixes both problems. Good work apple.

class SafeAreaFixTabBar: UITabBar { var oldSafeAreaInsets = UIEdgeInsets.zero @available(iOS 11.0, *) override func safeAreaInsetsDidChange() { super.safeAreaInsetsDidChange() if oldSafeAreaInsets != safeAreaInsets { oldSafeAreaInsets = safeAreaInsets invalidateIntrinsicContentSize() superview?.setNeedsLayout() superview?.layoutSubviews() } } override func sizeThatFits(_ size: CGSize) -> CGSize { var size = super.sizeThatFits(size) if #available(iOS 11.0, *) { let bottomInset = safeAreaInsets.bottom if bottomInset > 0 && size.height < 50 && (size.height + bottomInset < 90) { size.height += bottomInset } } return size } override var frame: CGRect { get { return super.frame } set { var tmp = newValue if let superview = superview, tmp.maxY != superview.frame.height { tmp.origin.y = superview.frame.height - tmp.height } super.frame = tmp } } } } 

Objective-C code:

 @implementation VSTabBarFix { UIEdgeInsets oldSafeAreaInsets; } - (void)awakeFromNib { [super awakeFromNib]; oldSafeAreaInsets = UIEdgeInsetsZero; } - (void)safeAreaInsetsDidChange { [super safeAreaInsetsDidChange]; if (!UIEdgeInsetsEqualToEdgeInsets(oldSafeAreaInsets, self.safeAreaInsets)) { [self invalidateIntrinsicContentSize]; if (self.superview) { [self.superview setNeedsLayout]; [self.superview layoutSubviews]; } } } - (CGSize)sizeThatFits:(CGSize)size { size = [super sizeThatFits:size]; if (@available(iOS 11.0, *)) { float bottomInset = self.safeAreaInsets.bottom; if (bottomInset > 0 && size.height < 50 && (size.height + bottomInset < 90)) { size.height += bottomInset; } } return size; } - (void)setFrame:(CGRect)frame { if (self.superview) { if (frame.origin.y + frame.size.height != self.superview.frame.size.height) { frame.origin.y = self.superview.frame.size.height - frame.size.height; } } [super setFrame:frame]; } @end 
+14
Nov 10 '17 at 15:01
source share

This is my way. Declare a subclass of UITabBar like ActionTabBar

swift 3.4

 class ActionTabBar: UITabBar { override var frame: CGRect { get { return super.frame } set { var tmp = newValue if let superview = self.superview, tmp.maxY != superview.frame.height { tmp.origin.y = superview.frame.height - tmp.height } super.frame = tmp } } } 

Objective-c

 @implementation ActionTabbar - (void)setFrame:(CGRect)frame { if (self.superview && CGRectGetMaxY(self.superview.bounds) != CGRectGetMaxY(frame)) { frame.origin.y = CGRectGetHeight(self.superview.bounds) - CGRectGetHeight(frame); } [super setFrame:frame]; } @end 
+9
Sep 26 '17 at 8:49
source share

Declare a subclass of NavigationController

  @implementation XXNavigationController - (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated { [super pushViewController:viewController animated:animated]; CGRect frame = self.tabBarController.tabBar.frame; frame.origin.y = [UIScreen mainScreen].bounds.size.height - frame.size.height; self.tabBarController.tabBar.frame = frame; } 
+2
Oct 18 '17 at 6:07
source share

Change: after release 12.1.1 this problem is fixed. You can keep the original structure.




If you change the structure

 UITabBarController -> UINavigationController -> UIViewController 

at

 UINavigationController -> UITabBarController -> UIViewController 

You will find that this problem is resolved. I really don't know why Apple is not fixing this problem.

In iOS 12.1, this problem becomes more serious. You can see how the text of the TabBar jumps above the TabBar every time you use the gesture to go back.

Note. This method may solve this problem, but I'm not sure if this is good. In addition, if your structure is quite complex, you need to change a lot of things.

+2
Nov 01 '18 at 0:45
source share

I have provided another solution for this error (it seems made by an apple).

and the solution should not prohibit tabs up, but so that the black area does not appear when moving the panel up

the kernel adds a subview to your viewcontroller because it is the deepest subview, and this view frame represents the size of the window. When the tab moves up, this preview will be shown instead of the black area

 if (@available(iOS 11.0, *)) { UIView* bgView = [[UIView alloc] initWithFrame:[UIScreen mainScreen].bounds]; bgView.autoresizingMask = UIViewAutoresizingNone; bgView.backgroundColor = UIColorFromRGB(0xefeff4); [self.view addSubview:bgView]; } 

the convenience of this method is that you do not have to subclass the tab or overwrite the pushcontroller method

0
Nov 23 '17 at 6:39
source share

this issue seems to be fixed in iOS 11.2

-3
Dec 26 '17 at 3:17
source share

You just need to add a launch image specifically for the iPhone X to the asset catalog (because it uses @ 3x) with a size of 1125 x 2436.

I hope this solves your problem.

-5
Oct 04 '17 at 9:54 on
source share



All Articles