为什么页面推动动画Tabbar在iPhone中移动X

为什么页面推动动画Tabbar在iPhone中移动X

问题描述:

我构建了一个应用程序Demo,使用hidesBottomBarWhenPushed隐藏了Tabbar中的Push Animation。为什么页面推动动画Tabbar在iPhone中移动X

Page Relationship

但是,当我点击跳转按钮的TabBar拉升!?是这样的: Tabbar Move up

+2

其中viewcontroller是你设置'hidesBottomBarWhenPushed'吗? – Lion

+0

在我的第一个图像中的最后一个ViewController,并且这个演示在其他iPhone设备上运行良好 – Tommy

+0

并且您发布的第二个屏幕截图看起来像是根据第一个截屏的屏幕截图,因为它显示了跳转按钮!如果你点击跳转按钮,那么你应该在最后一个屏幕和tabbar不应该在那里 – Lion

这是我的方式声明UITabBar的子类,如ActionTabBar

迅速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 
+3

其实它应该由苹果修复^^ – lukwuerz

+0

这解决了这个问题,但它会产生一个问题,一个模态segue,后面跟着一个push segue:https://imgur.com/a/MIHrF - 有没有人有同样的问题 – chronikum

+0

@chronikum看到我的答案波纹管解决了这两个问题。我也不得不在superview和tableview之间添加背景颜色视图,这在我的“主视图”(即有这两个节点)中是这样。 –

只需要将特定于iPhone X的启动图像添加到大小为11的资产目录(因为它使用@ 3x) 25 x 2436.

我希望这能解决您的问题。

+0

这有什么用?你测试过了吗?非常感谢。 –

+0

只是一个复制粘贴问题的答案“如何支持iphoneX”... –

声明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; 
    } 

一个子类修复的TabBar问题仅部分。它修复了tabbar中的布局问题,但是如果你使用隐藏tabbar的viewcontroller,在动画过程中tabbar会被错误地渲染(重现它最好是2有2个segues - 一个模式和一个push。)如果你改变了segues,你可以看到tabbar被排除在外)。看到解决这两个问题的代码。干得好苹果。

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代码:

@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 
+0

感谢您的回答,它适用于我。你能否解释一下硬编码值如何在你的解决方案中工作。如果(bottomInset> 0 && size.height

+0

在动画过程中,有一些超出我们控制范围的插入和高度的魔术。 if的第一部分修复了tabbar粘到视图的底部(如果我没有记错的话)。但是,如果您有两种不同的视图,使用模态和推送段显示,则会有副作用。基本上,如果您使用向后滑动手势,Tabbar的安全区域会无限增长,除非if的第二部分存在(在触发和重复之前,您开始向后滑动并释放它)。如果我记得正确的话,只有当navbar被隐藏并且在“push”视图之前看到“模态”视图时才会发生。 –

+0

非常感谢Raimundas!你今天是我的救世主! – Serzhas

我会为这个错误的另一个解决方案(似乎由苹果)。

和解决方案是不禁止的TabBar拉升,但要使时的TabBar拉升

核心就是一个子视图添加到您的视图 - 控制,因为它最深子视图的黑色区域将不会显示这个子视图的框架是当使用TabBar向上移动窗口size.so,此子视图会显示与其使用的黑色区域

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

} 

这种方法的便利性,你不会有子类的TabBar或覆盖navigationcontroller的push方法

这个问题似乎在iOS 11.2中修复了