我想在谷歌地图上临时显示一个广告横幅。
因此我有以下代码:
WPMapViewController.h:
#import <iAd/iAd.h>
....
@interface WPMapViewController : UIViewController<ADBannerViewDelegate, GMSMapViewDelegate>
WPMapViewController.m:
@implementation WPMapViewController {
GMSMapView *mapView_;
ADBannerView *_bannerView;
}
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
// On iOS 6 ADBannerView introduces a new initializer, use it when available.
if ([ADBannerView instancesRespondToSelector:@selector(initWithAdType:)]) {
_bannerView = [[ADBannerView alloc] initWithAdType:ADAdTypeBanner];
} else {
_bannerView = [[ADBannerView alloc] init];
}
_bannerView.delegate = self;
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
screenSize = [[UIScreen mainScreen] bounds].size;
GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:51.7
longitude:10.4
zoom:5.3];
mapView_ = [GMSMapView mapWithFrame:CGRectZero camera:camera];
self.view = mapView_;
mapView_.delegate = self;
_bannerView.frame = CGRectMake(0, screenSize.height - 50, 320, 50);
[self.view addSubview:_bannerView];
}
我猜是因为
self.view = mapView_;
_bannerView.delegate 被覆盖了。当我运行此代码时,我可以看到广告横幅,但无法单击它。self.view = mapView_;
时,横幅按预期工作,但我看不到地图。
self.canDisplayBannerAds = YES;
对我来说不是一个选择,因为它缩小了地图。
向此 UIViewController 添加 iAd 横幅的正确方法是什么?
我通过更改来修改你的来源
mapView_ = [GMSMapView mapWithFrame:CGRectZero camera:camera];
到
mapView_ = [GMSMapView mapWithFrame:self.view.frame camera:camera];
然后显示地图和 iAd 横幅,横幅位于屏幕底部。