cordova|phonegap 在ios下 控制 orientation。

 1 - (BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation   
 2 {  
 3     // First, ask the webview via JS if it supports the new orientation  
 4     NSString* jsCall = [NSString stringWithFormat:  
 5                         @"(function(){ \  
 6                                 if('shouldRotateToOrientation' in window) { \  
 7                                     return window.shouldRotateToOrientation(%d); \  
 8                                 } \  
 9                             })()"  
10                         , [self mapIosOrientationToJsOrientation:interfaceOrientation]];  
11     NSString* res = [webView stringByEvaluatingJavaScriptFromString:jsCall];  
12     NSLog(@"should");  
13     if([res length] > 0) {  
14         NSLog(@"inner");  
15         return [res boolValue];  
16     }  
17       
18     // if js did not handle the new orientation (no return value), use values from the plist (via supportedOrientations)  
19     return [self supportsOrientation:interfaceOrientation];  
20 }  

cordova|phonegap 在ios下 contorl orientation。

 

在CDVViewController.m下 有段代码: window.shouldRotateToOrientation();

这段代码在cordova2.1上,低版本是否有不确定。

ps 2.0上也有

当转屏时它会被依次调用4次,分别是4个方向。你需要返回 boolValue。

0  
180  
90  
-90  
对应的是  
portrait  
portraitUpsideDown  
landscapeRight  
landscapeLeft 

  

开发时,不同view可以修改你的js orientationHash 从而控制转屏方向。

比如: 

window.shouldRotateToOrientation = function(a){  
    //console.log("shouldRotateToOrientation:" + a);  
    return orientationHash[a];  
}  

猜想下andorid应当也有类似的方法吧。

posted @ 2012-11-29 14:02  阿水哥  阅读(298)  评论(0编辑  收藏  举报