2014-10-05 134 views
0

我有一个横向专用应用程序,我试图在iOS8上工作。我正在尝试创建横向视图底部显示的iAd横幅。但是,当显示广告标题时,它会在视图中心和纵向上显示。下面是我如何设置的意见:尽管窗口是横向的,但纵向方向的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]; 

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

+0

解决方案是什么? – ColdSteel 2015-04-18 23:05:25

回答

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的大小并将其放置在屏幕的顶部。