IOS中的电话间隙高度变化



我有一个简单的phonegap项目,我想在其中添加admob,我需要调整phonegap的高度,在屏幕顶部留出50dp的空间,在ipad上留出90dp,我不确定该怎么做,现在我只是在html文件中留出50dp空间,我将admob放在该html上方的屏幕顶部,如果我想在iPhone和iPad上使用智能横幅,我确信这不是正确的方式。

我试着用这个代码做一些修改,但没有成功,我相信还有另一种方法。

CGRect screenBounds = [[UIScreen mainScreen] bounds];
self.window = [[[UIWindow alloc] initWithFrame:screenBounds] autorelease];

您必须获取并更新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;

最新更新