【问题标题】:Phonegap height change in IOS?IOS中Phonegap高度变化?
【发布时间】:2013-08-22 21:43:02
【问题描述】:

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

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

CGRect screenBounds = [[UIScreen mainScreen] bounds];

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

【问题讨论】:

    标签: javascript html ios objective-c cordova


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 2018-05-23
      • 1970-01-01
      • 1970-01-01
      • 2016-10-04
      • 1970-01-01
      • 1970-01-01
      • 2013-10-10
      • 1970-01-01
      • 2015-01-21
      相关资源
      最近更新 更多