iPhone - 如何找到最顶层的视图控制器

  • (UIViewController*)topViewController {

return **self** topViewControllerWithRootViewController:\[UIApplication sharedApplication.keyWindow.rootViewController];

}

  • (UIViewController*)topViewControllerWithRootViewController:(UIViewController*)rootViewController {

if (rootViewController isKindOfClass:\[UITabBarController class]) {

UITabBarController* tabBarController = (UITabBarController*)rootViewController;

return **self** topViewControllerWithRootViewController:tabBarController.selectedViewController;

}

else if (rootViewController isKindOfClass:\[UINavigationController class]) {

UINavigationController *navigationController = (UINavigationController*)rootViewController;

return **self** topViewControllerWithRootViewController:navigationController.visibleViewController;

}

else if (rootViewController.presentedViewController) {

UIViewController* presentedViewController = rootViewController.presentedViewController;

return **self** topViewControllerWithRootViewController:presentedViewController;

}

else {

return rootViewController;

}

}

相关推荐
weixin_4038101323 分钟前
苹果群控带机量实测:一台电脑能稳定控多少台iPhone
自动化·iphone·跨境电商·苹果投屏·多媒体运营·安卓中控
weixin_4038101329 分钟前
iOS自动化脚本怎么避免风控?无屏幕镜像截图原理详解
ios·自动化·跨境电商·苹果群控·苹果投屏·多媒体运营
wangruofeng1 小时前
3 步把 MacBook 变成 7×24 远程主机,人在外面随时接管桌面
ios·agent·mac
weixin_403810131 小时前
iOS免越狱自动化蓝牙HID方案:不装代理也能跑脚本
运维·ios·自动化·跨境电商·ai智能体·ios投屏·苹果投屏
GitLqr13 小时前
Flutter 3.47 与 Dart 3.13:你必须了解的迁移指南
flutter·ios·dart
冯汉栩18 小时前
Swift Control View,Label渐变颜色(源码)
开发语言·ios·swift
jike_202620 小时前
iPhone日历查看会议纪要APP推荐:按日期查找历史录音更方便
ios·语音识别·iphone
冯汉栩1 天前
OC 技术 App上存蒲公英教程
ios
码云之上2 天前
小程序 iOS 多输入框焦点乱序脱坑记
ios·微信小程序·taro
2501_915909062 天前
iOS test 测试怎么做?功能、性能、兼容、稳定与安全五类测试指南
android·ios·小程序·https·uni-app·iphone·webview