即使窗口是风景,iAd横幅也以纵向显示

时间:2014-10-05 21:45:15

标签: uiviewcontroller ios8 iad

我有一个只有风景的应用程序,我试图在iOS8上工作。我正在尝试创建一个显示在横向视图底部的iAd横幅。但是,当广告横幅显示时,它会在视图中心和纵向显示。以下是我设置视图的方式:

app = (AppDelegate *)[[UIApplication sharedApplication] delegate];

// Init the Ad View Controller (viewController is defined as a UIViewController)
viewController = [[AdViewController alloc] initWithNibName:nil bundle:nil];

// Create a banner view controller and make the adViewController be the content controller for the bannerViewController
bannerViewController = [[BannerViewController alloc] initWithContentViewController:viewController];

[app.window addSubview:bannerViewController.view]; 

请注意,如果我在此代码中测试statusBarOrientation,则会显示方向为横向。另请注意,如果我更改最后一行,将bannerViewController.view添加到窗口的根视图中,如下所示:

[app.nrViewController.view addSubview:bannerViewController.view];

结果是一样的。具体而言,广告横幅显示在视图的中心和纵向方向上。横幅视图是否应该以与其父视图相同的方向显示?

1 个答案:

答案 0 :(得分:0)

似乎很多开发人员遇到了这个问题,但我没有找到任何答案。以下是我修复它的方法:

我以编程方式将iAd添加到我的ViewController中,如下所示:

ViewController.h:

ADBannerView *_iadView;

然后在(ViewController.m)viewDidLoad:

CGRect adRect = CGRectZero;

//this is what fixed the issue
adRect.size.width = self.view.bounds.size.width; 

_iadView = [[ADBannerView alloc] initWithFrame:adRect];

CGRect adFrame = _iadView.frame;
adFrame.origin.y = -_iadView.frame.size.height;
_iadView.frame = adFrame;

[_iadView setAutoresizingMask:UIViewAutoresizingFlexibleWidth];

[self.view addSubview:_iadView];

以上将正确调整iAd的大小并将其放在屏幕顶部。

相关问题