2014-10-05 79 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的大小並將其放置在屏幕的頂部。

相關問題