iOS11适配相关iOS备忘录ios

iOS开发: 解决iPhoneX模拟器上push过程中tabBa

2017-09-21  本文已影响1615人  伯wen

提示: 本篇以Swift代码讲解, 最下面为OC代码, 如果有问题请留言

问题描述
解决思路
override func pushViewController(_ viewController: UIViewController, animated: Bool) {
    super.pushViewController(viewController, animated: animated)
}
override func pushViewController(_ viewController: UIViewController, animated: Bool) {
    if childViewControllers.count > 0 {
           // push时隐藏tabBar
           viewController.hidesBottomBarWhenPushed = true
    }
    super.pushViewController(viewController, animated: animated)
}
override func pushViewController(_ viewController: UIViewController, animated: Bool) {
    if childViewControllers.count > 0 {
           // push时隐藏tabBar
           viewController.hidesBottomBarWhenPushed = true
    }
    super.pushViewController(viewController, animated: animated)
    
    // 获取tabBar的frame, 如果没有直接返回
    guard var frame = self.tabBarController?.tabBar.frame else {
        return
    }
    // 设置frame的y值, y = 屏幕高度 - tabBar高度
    frame.origin.y = UIScreen.main.bounds.size.height - frame.size.height
    // 修改tabBar的frame
    self.tabBarController?.tabBar.frame = frame
}
最后效果
OC版本代码如下:
- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated {
    if (self.childViewControllers.count > 0) {
        // push过程中隐藏tabBar
        viewController.hidesBottomBarWhenPushed = YES;
    }
    
    // 重写super
    [super pushViewController:viewController animated:animated];
    
    // 修改tabBra的frame
    CGRect frame = self.tabBarController.tabBar.frame;
    frame.origin.y = [UIScreen mainScreen].bounds.size.height - frame.size.height;
    self.tabBarController.tabBar.frame = frame;
}
上一篇下一篇

猜你喜欢

热点阅读