【问题标题】:How to place admob banner at bottom of screen in iOS retina and non retina如何在 iOS 视网膜和非视网膜的屏幕底部放置 admob 横幅
【发布时间】:2013-01-28 14:19:51
【问题描述】:

我已经构建了一个 phonegap 应用,并想向它添加一个 Admob 横幅。我的横幅在 iOS6 模拟器的屏幕底部工作,但是当我在视网膜设备上对其进行测试时,横幅将远离底部,就像它仍在尝试为非视网膜显示调整屏幕大小一样。这是我当前在 viewDidLoad 中的代码:

// Initialize the banner at the bottom of the screen.
CGPoint origin = CGPointMake(0.0,
                             self.view.frame.size.height -
                             CGSizeFromGADAdSize(kGADAdSizeBanner).height);

// Use predefined GADAdSize constants to define the GADBannerView.
bannerView_ = [[GADBannerView alloc] initWithAdSize:kGADAdSizeBanner
                                             origin:origin];

// Specify the ad's "unit identifier." This is your AdMob Publisher ID.
bannerView_.adUnitID = @"xxxxxxxxxxxx";

// Let the runtime know which UIViewController to restore after taking
// the user wherever the ad goes and add it to the view hierarchy.
bannerView_.rootViewController = self;
[self.view addSubview:bannerView_];

// Initiate a generic request to load it with an ad.
[bannerView_ loadRequest:[GADRequest request]];

【问题讨论】:

    标签: iphone ios objective-c cordova


    【解决方案1】:

    你可以试试这个,

    bannerView_ = [[GADBannerView alloc] initWithFrame:CGRectMake(0.0, self.view.frame.size.height-GAD_SIZE_320x50.height, GAD_SIZE_320x50.width, GAD_SIZE_320x50.height)];
    

    【讨论】:

      【解决方案2】:

      我通过将上述代码从viewDidLoad 移动到webViewDidFinishLoad 解决了这个问题。

      【讨论】:

        【解决方案3】:

        我用这段代码来计算 NavigationBar 和 Status Bar:

        CGPoint origin = CGPointMake(0.0,
                                     self.view.frame.size.height -
                                     CGSizeFromGADAdSize(kGADAdSizeBanner).height -
                                     self.navigationController.navigationBar.frame.size.height -
                                     20 /* status bar */);
        

        【讨论】:

          【解决方案4】:

          我没有测试你的代码,所以它可能已经在工作了,但是使用非原点初始化并在之后重置原点似乎有效:

          bannerView_ = [[GADBannerView alloc] initWithAdSize:kGADAdSizeBanner];
          
          // Omitted: set up ad id, etc
          
          CGRect frame = bannerView_.frame;
          frame.origin.y = self.view.frame.size.height - frame.size.height;
          bannerView_.frame = frame;
          
          [self.view addSubview:bannerView_];
          

          【讨论】:

            猜你喜欢
            • 2014-03-19
            • 2014-01-13
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2013-02-10
            • 1970-01-01
            相关资源
            最近更新 更多