1***@163.com
1***@163.com
  • 发布:2023-06-20 17:36
  • 更新:2023-06-20 23:24
  • 阅读:183

iOS 插件如何获取根试图rootViewController 我想使用原生的UI pushViewController 过去

分类:uni-app

iOS 插件如何获取根试图rootViewController 我想使用原生的UI pushViewController 过去

2023-06-20 17:36 负责人:无 分享
已邀请:
FullStack

FullStack - 【插件开发】【专治疑难杂症】【ios上架、马甲包、白包、过审、已成功上架过几百个】【多款插件已上架:https://ext.dcloud.net.cn/publisher?id=22130】【非诚勿扰】QQ:543610866

相关文档:https://nativesupport.dcloud.net.cn/NativePlugin/course/ios.html#q-%E5%A6%82%E4%BD%95%E8%B7%B3%E8%BD%AC%E5%8E%9F%E7%94%9F-uiviewcontroller

// 获取当前显示的 UIViewController  
+ (UIViewController *)dc_findCurrentShowingViewController {  
    //获得当前活动窗口的根视图  
    UIViewController *vc = [UIApplication sharedApplication].keyWindow.rootViewController;  
    UIViewController *currentShowingVC = [self findCurrentShowingViewControllerFrom:vc];  
    return currentShowingVC;  
}  
+ (UIViewController *)findCurrentShowingViewControllerFrom:(UIViewController *)vc  
{  
    // 递归方法 Recursive method  
    UIViewController *currentShowingVC;  
    if ([vc presentedViewController]) {  
        // 当前视图是被presented出来的  
        UIViewController *nextRootVC = [vc presentedViewController];  
        currentShowingVC = [self findCurrentShowingViewControllerFrom:nextRootVC];  

    } else if ([vc isKindOfClass:[UITabBarController class]]) {  
        // 根视图为UITabBarController  
        UIViewController *nextRootVC = [(UITabBarController *)vc selectedViewController];  
        currentShowingVC = [self findCurrentShowingViewControllerFrom:nextRootVC];  

    } else if ([vc isKindOfClass:[UINavigationController class]]){  
        // 根视图为UINavigationController  
        UIViewController *nextRootVC = [(UINavigationController *)vc visibleViewController];  
        currentShowingVC = [self findCurrentShowingViewControllerFrom:nextRootVC];  

    } else {  
        // 根视图为非导航类  
        currentShowingVC = vc;  
    }  

    return currentShowingVC;  
}  

要回复问题请先登录注册