cordova项目多个原生界面间过场动画配置

本人ios小白,最近做混生开发(cordova + ionic + angularjs),由于对ios机制完全不理解,只能遇见一个问题解决一个问题了。
项目需要打开外部网页,但是某条的网址有判断,不允许外部html引用,所以只能硬着头皮写原生界面来通过webview展示了(原生界面产生的原因)。
在网上看到要设置过场动画需要UINavigationController这么个东西,可是cordova生成的OC代码并没有(也可能是没有找到,说了我是小白),各种尝试后,终于实现了。

 1 - (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions
 2 {
 3 //    这里是原来cordova生成的代码吧,改了好久了,记不清楚了    
 4 //    self.viewController = [[MainViewController alloc] init];
 5 
 6     self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
 7     self.window.backgroundColor = [UIColor whiteColor];
 8     MainViewController *root = [[MainViewController alloc]init];
 9     UINavigationController *nav =[[UINavigationControlleralloc]initWithRootViewController:root];//先将root添加在navigation上
10     [nav setNavigationBarHidden:YES];
11     [self.window setRootViewController:nav];//navigation加在window上
12 
13     //  侧滑返回
14     nav.interactivePopGestureRecognizer.enabled = YES;
15     nav.interactivePopGestureRecognizer.delegate =(id)self;
16 
17     [self.window makeKeyAndVisible];
18     return YES;
19 }
上面应该就是构造了一个UINavigationController。
在使用的时候,大概就是取到当前的根视图吧。

 1 UINavigationController *result = nil;
 2     UIWindow * window = [[UIApplication sharedApplication] keyWindow];
 3     if (window.windowLevel != UIWindowLevelNormal)
 4     {
 5         NSArray *windows = [[UIApplication sharedApplication] windows];
 6         for(UIWindow * tmpWin in windows)
 7         {
 8             if (tmpWin.windowLevel == UIWindowLevelNormal)
 9             {
10                 window = tmpWin;
11                 break;
12             }
13         }
14     }
15 
16     UIView *frontView = [[window subviews] objectAtIndex:0];
17     id nextResponder = [frontView nextResponder];
18 
19     if ([nextResponder isKindOfClass:[UIViewController class]])
20         result = nextResponder;
21     else
22         result = (UINavigationController*)window.rootViewController;
23 
24     // 将要展示的页面push进去 即可
25     EvidenceDetailViewController *edv = [[EvidenceDetailViewController alloc]init];
26     [result pushViewController:edv animated:YES];
最开始是没有做侧滑返回的,今天需求提出来了,又和这块打交道了,就整理了下。





侧滑返回参考文章:http://blog.sina.com.cn/s/blog_65c178a80102v0f4.html
posted @ 2016-10-19 17:31  freedom_sure  阅读(124)  评论(0)    收藏  举报