0

我有一个简单的phonegap项目,我想添加admob,我需要规定phonegap高度以在屏幕顶部留下50dp的空间,在ipad上留下90dp,我不确定如何做到这一点,现在我只是在 html 文件中留下了 50dp 的空间,我将 admob 放在该 html 上方的屏幕顶部,如果我想为 Iphone 和 ipad 使用智能横幅,我确定这不是正确的方法。

我尝试使用此代码进行一些更改,但没有运气,我确定还有另一种方法。

CGRect screenBounds = [[UIScreen mainScreen] bounds];

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

1 回答 1

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;
于 2013-08-22T22:51:49.010 回答