2013-08-22 394 views
0

我有一個簡單的phonegap項目,我想添加admob它,我需要制定手機高度在屏幕頂部留下50dp空間,並在ipad上留下90dp,我不知道如何做到這一點,現在我剛剛在html文件中留下了50dp的空間,我把admob放在html上面的屏幕頂部,如果我想爲iPhone和iPad使用智能橫幅,那麼確定這不是正確的方法。IOS中的手機高度變化?

我試着做這個代碼的一些變化,但沒有運氣,我確定有另一種方式。

CGRect screenBounds = [[UIScreen mainScreen] bounds]; 

self.window = [[[UIWindow alloc] initWithFrame:screenBounds] autorelease]; 

回答

0

您必須獲取並更新webView框架。類似下面那樣也支持屏幕旋轉:

// detect orientation 
UIDeviceOrientation currentOrientation = [[UIDevice currentDevice] orientation]; 
BOOL isLandScape = (UIInterfaceOrientationIsLandscape(currentOrientation)); 

CGRect webViewFrame = webView.frame; 
CGRect superViewFrame = webView.superview.frame; 
CGRect bannerViewFrame = bannerView.frame; 

// Frame of the main Cordova webview and its max size 
CGFloat webViewHeight = superViewFrame.size.height; 

// define height for banner, 0 if hidden 
CGFloat bannerHeight = bannerViewFrame.size.height; 

if (bannerView.hidden){ 
    bannerHeight = 0.0; 
} 

// set different size for landscape 
if (isLandScape) { 
    webViewHeight = superViewFrame.size.width; 
} 

webViewHeight -= bannerHeight; 
webViewFrame.size.height = webViewHeight; 

// move webview x location 
webViewFrame.origin.x = bannerHeight; 

// finally set the frame 
webView.frame = webViewFrame;