即使窗口是风景,iAd横幅也以纵向显示 [英] iAd Banner Displays With Portrait Orientation Even Though Window is Landscape

查看:133
本文介绍了即使窗口是风景,iAd横幅也以纵向显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have a landscape only app that I am trying to get working on iOS8. I am trying to create an iAd banner that displays across the bottom of the landscape view. However, when the ad banner displays, it displays across the center of the view and in a portrait orientation. Here is how I set up the views:

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添加到窗口的根视图中,如下所示:

Note that if I test the statusBarOrientation within this code, it shows that the orientation is landscape. Also note that if I change the last line to add the bannerViewController.view to the root view of the window as shown below:

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

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

the result is the same. Specifically, the ad banner displays across the center of the view and in a portrait orientation. Shouldn't the bannerView be displayed in the same orientation as its parent?

推荐答案

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

Seems like a lot of devs have run into this problem, and I didn't find any answers. Here's how I fixed it:

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

I programmatically add the iAd to my ViewController like this:

ViewController.h :

ViewController.h:

ADBannerView *_iadView;

然后在(ViewController.m)viewDidLoad:

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

The above will size the iAd correctly and place it on the top of the screen.

这篇关于即使窗口是风景,iAd横幅也以纵向显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆