从横向模式启动时 iAd 不适合宽度

发布于 2025-01-06 17:33:08 字数 844 浏览 0 评论 0原文

我在纵向和横向模式下正确切换和缩放 iAd,除非视图从横向模式开始。在这种情况下,iAd 保持与肖像相对应的窄宽度。然后,当将设备旋转到纵向并返回横向时,问题就解决了。怎么解决呢?谢谢。

- (void)viewDidLoad
{   
    //iAd

    adView =[[ADBannerView alloc] initWithFrame:CGRectZero];

    adView.requiredContentSizeIdentifiers = [NSSet setWithObjects: ADBannerContentSizeIdentifierPortrait, ADBannerContentSizeIdentifierLandscape, nil];

    adView.delegate = self;

    [self.view addSubview:adView];

    [super viewDidLoad];
}


- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)orientation duration:(NSTimeInterval)duration {

    if (UIInterfaceOrientationIsPortrait(orientation)) {
        adView.currentContentSizeIdentifier = ADBannerContentSizeIdentifierPortrait;
    } else {
        adView.currentContentSizeIdentifier = ADBannerContentSizeIdentifierLandscape;
    }

}

I am switching and scaling properly iAd on portraid and landscape mode excepts when view starts from landscape mode. In this case, iAd remains at narrow width that corresponds to portraid. Then when rotate the device to portraid and back to landscape, is solved. How to solve it? Thank you.

- (void)viewDidLoad
{   
    //iAd

    adView =[[ADBannerView alloc] initWithFrame:CGRectZero];

    adView.requiredContentSizeIdentifiers = [NSSet setWithObjects: ADBannerContentSizeIdentifierPortrait, ADBannerContentSizeIdentifierLandscape, nil];

    adView.delegate = self;

    [self.view addSubview:adView];

    [super viewDidLoad];
}


- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)orientation duration:(NSTimeInterval)duration {

    if (UIInterfaceOrientationIsPortrait(orientation)) {
        adView.currentContentSizeIdentifier = ADBannerContentSizeIdentifierPortrait;
    } else {
        adView.currentContentSizeIdentifier = ADBannerContentSizeIdentifierLandscape;
    }

}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

坚持沉默 2025-01-13 17:33:08

您没有告诉 adView 以哪个方向开始,因此它以默认方向开始。

尝试在 viewDidLoad 中添加以下内容:

if (UIInterfaceOrientationIsPortrait([UIDevice currentDevice].orientation)) {
    adView.currentContentSizeIdentifier = ADBannerContentSizeIdentifierPortrait;
} else {
    adView.currentContentSizeIdentifier = ADBannerContentSizeIdentifierLandscape;
}
[self.view addSubview:adView];

You do not tell the adView with which orientation to start, so it starts with the default orientation.

Try adding the following in viewDidLoad:

if (UIInterfaceOrientationIsPortrait([UIDevice currentDevice].orientation)) {
    adView.currentContentSizeIdentifier = ADBannerContentSizeIdentifierPortrait;
} else {
    adView.currentContentSizeIdentifier = ADBannerContentSizeIdentifierLandscape;
}
[self.view addSubview:adView];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文