参考:https://www.jianshu.com/p/3d79f3ac6a13
https://www.jianshu.com/p/981f6c496a82
场景:RN项目需跳转到高德离线地图界面,但不能进行导航跳转
解决:
在AppDelegate里添加导航并隐藏NavBar
RCTRootView *rootView = [[RCTRootView alloc] initWithBundleURL:jsCodeLocation
moduleName:@"AiYou"
initialProperties:nil
launchOptions:launchOptions];
rootView.backgroundColor = [[UIColor alloc] initWithRed:1.0f green:1.0f blue:1.0f alpha:1];
self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
UIViewController *rootViewController = [UIViewController new];
rootViewController.view = rootView;
_nav = [[UINavigationController alloc]initWithRootViewController:rootViewController];
self.window.rootViewController = _nav;
然后新建类继承MAOfflineMapViewController
通过RN传递点击事件进行跳转并显现NavBar
//跳转到d离线地图
RCT_EXPORT_METHOD(pushOfflineMapViewController){
dispatch_async(dispatch_get_main_queue(), ^{
AppDelegate *app = (AppDelegate *)[[UIApplication sharedApplication] delegate];
[app.nav setNavigationBarHidden:NO animated:YES];
OfflineMapViewController *detailViewController = [[OfflineMapViewController alloc] init];
[app.nav pushViewController:detailViewController animated:YES];
});
}
然后在继承的controller里实现viewWillDisappear方法隐藏NavBar
-(void)viewWillDisappear:(BOOL)animated{
[super viewWillDisappear:animated];
AppDelegate *app = (AppDelegate *)[[UIApplication sharedApplication] delegate];
[app.nav setNavigationBarHidden:YES animated:YES];
}