2010-07-21 72 views

回答

0

如果您不熟悉phonegap,请查看Jonathan Stark's great introduction

如果您已经熟悉phonegap并只需要一段代码,那么请查看bug报告here。正如您所看到的,在当前版本中,WatchOrientation似乎存在一些问题,但Shazron提供了我在此处复制的解决方法:

function onDeviceReady() 
{ 
    // do your thing! 
    document.addEventListener("orientationChanged", UpdateOrientation); 

} 

function UpdateOrientation(e) 
    { 
     switch(e.orientation) 
     { 
      case 0: // portrait 
      case 180: // portrait 
     // do your thing here 
       break; 
      case -90: // landscape 
      case 90: // landscape 
     // do your thing here 
       break; 
     }  
    }