iOS 26手势返回到根页面时TabBar的动效问题

问题描述

我在适配完iOS 26时发现一个很奇怪的问题:

在第一次手势返回根页面时,tabBar没有渐显动画直接显示在顶部。但是如果第一次没有返回,再次手势返回时则有渐显动效。如下图所示:(测试设备iPhone 17;iOS 26.2)

图片

代码实现

一开始代码实现如下,在跳页的时候使用hidesBottomBarWhenPushed来隐藏tabBar

ini 复制代码
SecondVC *secondVC = [[SecondVC alloc] init];
secondVC.titleName = @"首页";
secondVC.hidesBottomBarWhenPushed = YES; // 隐藏tabbar
UIViewController *currentVC = self.window.rootViewController;
if ([currentVC isKindOfClass:[UITabBarController class]]) {
   UITabBarController *tabBarController = (UITabBarController *)currentVC;
   UINavigationController *homeNav = (UINavigationController *)tabBarController.viewControllers[0];
   [homeNav pushViewController:secondVC animated:YES];
}

后面经过测试,发现使用[tabBarController setTabBarHidden:NO animated:animated]; 就正常渐显了。

关键代码如下

  1. 创建首页的UINavigationController时设置代理
ini 复制代码
RootTabBarController *tabBarController = [[RootTabBarController alloc] init];
    self.tabController = tabBarController;
    
    // 设置首页tab
    UINavigationController *homeNav = [[UINavigationController alloc] initWithRootViewController:homeVC];
    homeNav.tabBarItem.title = @"首页";
    homeNav.tabBarItem.image = [UIImage systemImageNamed:@"house"];
    // 设置代理
    homeNav.delegate = tabBarController;
    
    // 设置我的tab
    UINavigationController *profileNav = [[UINavigationController alloc] initWithRootViewController:profileVC];
    profileNav.tabBarItem.title = @"我的";
    profileNav.tabBarItem.image = [UIImage systemImageNamed:@"person"];
    // 设置代理
    profileNav.delegate = tabBarController;
    
    [tabBarController setViewControllers:@[homeNav, profileNav]];
    self.window.rootViewController = tabBarController;
    [self.window makeKeyAndVisible];
  1. 实现 UINavigationControllerDelegate
objectivec 复制代码
#pragma mark - UINavigationControllerDelegate

- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated {
    // 判断是否为根视图控制器
    if ([navigationController.viewControllers indexOfObject:viewController] == 0) {
        // 返回到根页面,显示tabbar
        [self setTabBarHidden:NO animated:animated];
    } else {
        // 跳转到子页面,隐藏tabbar
        [self setTabBarHidden:YES animated:animated];
    }
}

以上,希望有帮助到大家

相关推荐
初级代码游戏13 小时前
iOS开发 Swift 速记1:变量和基本数据类型
开发语言·ios·swift
for_ever_love__14 小时前
iOS:网络请求再学习
网络·学习·ios·objective-c
2501_9159214319 小时前
SwiftUI开发框架入门指南:从基础到实战
ide·vscode·ios·objective-c·个人开发·swift·敏捷流程
2501_9160074721 小时前
Python实现HTTPS爬虫的完整指南:使用requests、BeautifulSoup、Selenium和Scrapy
爬虫·python·ios·小程序·https·uni-app·iphone
LDyun_1 天前
云手机低延迟怎么实现的?为什么云手机能够 7×24 小时在线?
ios·智能手机·安卓·玩游戏
for_ever_love__1 天前
iOS: 网络请求第三方库的使用: AFNetworking
网络·学习·ios·objective-c·cocoa·xcode
李白你好1 天前
强大的 Frida 重打包工具,用于 iOS 和 Android。轻松修改 Frida 特征
android·ios
zhao1zhihui2 天前
iOS Bug 定位实战:从断点、LLDB 到 Xcode 与 Instruments
ios·xcode
zhao1zhihui2 天前
Objective-C Runtime:从消息派发到安全 Hook
ios
GitLqr2 天前
Flutter FocusNode 实战指南:玩转键盘焦点与用户输入体验
android·flutter·ios