美文网首页
iOS开发实战小知识点(六)——iPhone X后 Push V

iOS开发实战小知识点(六)——iPhone X后 Push V

作者: Eddiegooo | 来源:发表于2017-10-24 09:25 被阅读91次
    问题: 在iPhone X 以后机型切换Push VC过程中,Tabbar会先上移一下,不知道苹果怎么搞的,iPhone X系列适配真是坑爹啊,不,是坑儿子。 O(∩_∩)O哈哈~

    慢动作图看下效果:

    tabbar上移1.gif

    解决办法:

    重写这个- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated方法,重新设置下Tabbar 的frame:

    /**
     *  重写这个方法,能拦截所有的push操作
     */
    - (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated {
        if (self.viewControllers.count > 0) {
            viewController.hidesBottomBarWhenPushed = YES;
        }
        [super pushViewController:viewController animated:animated];
        // 修改tabBra的frame iPhone X切换切面tabbar上移bug修复
        CGRect frame = self.tabBarController.tabBar.frame;
        frame.origin.y = [UIScreen mainScreen].bounds.size.height - frame.size.height;
        self.tabBarController.tabBar.frame = frame;
    }
    

    修复后效果:

    tabbar上移修复.gif
    tips:判断iPhone X系列手机方法:
     NS_INLINE BOOL isIPhoneXSeries() {
        BOOL iPhoneXSeries = NO;
        if (UIDevice.currentDevice.userInterfaceIdiom != UIUserInterfaceIdiomPhone) {
            return iPhoneXSeries;
        }
        if (@available(iOS 11.0, *)) {
            UIWindow *mainWindow = [[[UIApplication sharedApplication] delegate] window];
            if (mainWindow.safeAreaInsets.bottom > 0.0) {
                iPhoneXSeries = YES;
            }
        }
        return iPhoneXSeries;
    }
    

    参考文章:适配 iPhone X Push 过程中 TabBar 位置上移

    相关文章

      网友评论

          本文标题:iOS开发实战小知识点(六)——iPhone X后 Push V

          本文链接:https://www.haomeiwen.com/subject/feqtpxtx.html