iAd 景观奇怪的视图行为

发布于 2024-11-03 11:03:21 字数 1680 浏览 4 评论 0原文

我有一个 iAd,它显示在主视图的全屏子视图的顶部。 iAd 在纵向模式下正常工作,并且我已将 iAd 横幅视图旋转为横向模式。当用户在横向模式下点击 iAd 时,会出现此问题。测试广告以纵向、横向方式显示在手机上,当用户点击 x 关闭 iAd 时,横幅视图及其父视图将被推离屏幕。 iAd 在纵向模式下表现正常(即点击它并关闭它会导致包含横幅的视图正常显示)。

我尝试过的事情:

- (void)bannerViewActionDidFinish:(ADBannerView *)banner{
NSLog(@"Ad was closed, show the adView again");
if(UIInterfaceOrientationIsLandscape(currentInterfaceOrientation)){
    [self animateRotationToLandscape:0.3f];
}
else{
    [self animateRotationToPortrait:0.3f];
}
}

-(void)animateRotationToPortrait:(NSTimeInterval)duration{
    self.adView.currentContentSizeIdentifier =
    ADBannerContentSizeIdentifierPortrait;

    BOOL iPad = NO;
    #ifdef UI_USER_INTERFACE_IDIOM
    iPad = (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad);
    #endif

    if (iPad) {
        [UIView beginAnimations:nil context:nil];
        [UIView setAnimationDuration:duration];
        proUpgradeDescription.frame = CGRectMake(82,313,604,110);
        proUpgradePrice.frame = CGRectMake(313,576,142,28);
        closeButton.frame = CGRectMake(348,834,72,37);
        purchaseButton.frame = CGRectMake(313,431,142,142);
        [UIView commitAnimations];
    }
    else{
        [UIView beginAnimations:nil context:nil];
        [UIView setAnimationDuration:duration];
        proUpgradeDescription.frame = CGRectMake(20,80,280,70);
        proUpgradePrice.frame = CGRectMake(88,322,142,28);
        closeButton.frame = CGRectMake(123,403,72,37);
        purchaseButton.frame = CGRectMake(88,172,142,142);
        [UIView commitAnimations];
    }
}

它调用了我用来为纵向和横向模式的显示器旋转设置动画的代码。这段代码没有任何作用。

如果有人对为什么测试广告不能正确旋转以及为什么它们将父视图控制器推离屏幕有任何想法,我将不胜感激。

I have an iAd which displays at the top of a fullscreen subview of the main view. The iAd works normally in portrait mode, and I have handled rotation of the iAd banner view into landscape mode. The issue occurs when the iAd is tapped by the user in landscape mode. The test advertisement displays in portrait, sideways on the phone, and when the user taps the x to dismiss the iAd, the banner view and its parent view are pushed offscreen. The iAd behaves normally in portrait mode (i.e. tapping it and closing it results in the view containing the banner to be displayed normally).

Things I have tried:

- (void)bannerViewActionDidFinish:(ADBannerView *)banner{
NSLog(@"Ad was closed, show the adView again");
if(UIInterfaceOrientationIsLandscape(currentInterfaceOrientation)){
    [self animateRotationToLandscape:0.3f];
}
else{
    [self animateRotationToPortrait:0.3f];
}
}

-(void)animateRotationToPortrait:(NSTimeInterval)duration{
    self.adView.currentContentSizeIdentifier =
    ADBannerContentSizeIdentifierPortrait;

    BOOL iPad = NO;
    #ifdef UI_USER_INTERFACE_IDIOM
    iPad = (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad);
    #endif

    if (iPad) {
        [UIView beginAnimations:nil context:nil];
        [UIView setAnimationDuration:duration];
        proUpgradeDescription.frame = CGRectMake(82,313,604,110);
        proUpgradePrice.frame = CGRectMake(313,576,142,28);
        closeButton.frame = CGRectMake(348,834,72,37);
        purchaseButton.frame = CGRectMake(313,431,142,142);
        [UIView commitAnimations];
    }
    else{
        [UIView beginAnimations:nil context:nil];
        [UIView setAnimationDuration:duration];
        proUpgradeDescription.frame = CGRectMake(20,80,280,70);
        proUpgradePrice.frame = CGRectMake(88,322,142,28);
        closeButton.frame = CGRectMake(123,403,72,37);
        purchaseButton.frame = CGRectMake(88,172,142,142);
        [UIView commitAnimations];
    }
}

Which calls code that I use to animate rotation of the display for portrait and landscape mode. This code has no effect.

If anyone has any ideas as to why the test advertisements don't rotate correctly and why they push the parent view controller off the screen I would greatly appreciate it.

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

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

发布评论

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

评论(3

情定在深秋 2024-11-10 11:03:21

我不知道这是否解决了您的所有问题,但根据

I don't know if this addresses all of your problems, but according to the answer on this question, the test ads are only in portrait, and real ads will show up in both orientations.

棒棒糖 2024-11-10 11:03:21

我知道这个问题有点老了,所以我在这里发帖,以防万一有人遇到同样的问题(我就是这样做的)。

ADBannerView 会与父视图的框架和变换属性混淆,因此您所要做的就是在完成后将它们重置为原始值(在 bannerViewActionDidFinish: 中)。

我仍然不明白为什么它完成后没有将所有内容恢复原样。我们不应该这样做。

I know the question is a little old so I'm posting here just in case someone runs into the same problem (I did).

ADBannerView messes with the frame and transform properties of the parent view so all you have to do is to reset them to their original values after it has finished (in bannerViewActionDidFinish:).

I still don't understand why it doesn't put back everything the way it was after it has finished. We shouldn't have to do this.

满地尘埃落定 2024-11-10 11:03:21

这也让我抓狂。仅向 iPad 提供横向整页广告,向 iPhone 提供纵向整页广告,而不明说是自找麻烦。我放弃使用 iAdSuite 代码,该代码导致横向 iPad 广告即使在设备处于纵向状态时也会以横向方式离开屏幕!

这是我的横幅广告代码。这一切都在加载的第一个视图控制器中。它的目的是将横幅放在屏幕底部。

在头文件中:

#import "iAd/ADBannerView.h"

@property (strong, nonatomic) ADBannerView* adView;

@interface myViewController : UIViewController <ADBannerViewDelegate,

在 vi​​ewDidLoad

CGRect contentFrame = self.view.bounds;
CGRect bannerFrame = CGRectZero;
bannerFrame.size = [adView sizeThatFits:contentFrame.size];
bannerFrame.origin.y = contentFrame.size.height-bannerFrame.size.height;
adView = [[ADBannerView alloc] initWithFrame:bannerFrame];
[adView setDelegate:self];
[self.view addSubview:adView];

然后

-(void)viewWillLayoutSubviews {
       CGRect contentFrame = self.view.bounds;
       CGRect bannerFrame=CGRectZero;
       bannerFrame.size = [adView sizeThatFits:contentFrame.size];
      if (adView.bannerLoaded) {bannerFrame.origin.y = contentFrame.size.height-bannerFrame.size.height;}
      else {bannerFrame.origin.y = contentFrame.size.height;}
      [adView setFrame:bannerFrame];}

然后 为了处理来自 iAd 的回调,我们需要告诉视图在发生变化时重做其布局:

- (void)bannerViewDidLoadAd:(ADBannerView *)banner{
[UIView animateWithDuration:0.25 animations:^{
    [self.view setNeedsLayout];
    [self.view layoutIfNeeded];
}];}

- (void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error{
[UIView animateWithDuration:0.25 animations:^{
    [self.view setNeedsLayout];
    [self.view layoutIfNeeded];
}];}

这似乎可以在 iPad 和 iPhone 上正确处理方向,除了测试整页广告之外。然而,在测试广告被关闭后,屏幕呈现正确的方向,所以我希望一切顺利。

This drove me nuts too. Delivering only landscape full page ads to the iPad and portrait to the iPhone and not saying so is asking for trouble. I gave up using the iAdSuite code, which caused the Landscape iPad ad to leave the screen in Landscape even when the device was in portrait!

This is my code for banner ads. It is all in the first view controller loaded. It aims to put the banner at the bottom of the screen.

In the header file:

#import "iAd/ADBannerView.h"

@property (strong, nonatomic) ADBannerView* adView;

@interface myViewController : UIViewController <ADBannerViewDelegate,

in viewDidLoad

CGRect contentFrame = self.view.bounds;
CGRect bannerFrame = CGRectZero;
bannerFrame.size = [adView sizeThatFits:contentFrame.size];
bannerFrame.origin.y = contentFrame.size.height-bannerFrame.size.height;
adView = [[ADBannerView alloc] initWithFrame:bannerFrame];
[adView setDelegate:self];
[self.view addSubview:adView];

Then

-(void)viewWillLayoutSubviews {
       CGRect contentFrame = self.view.bounds;
       CGRect bannerFrame=CGRectZero;
       bannerFrame.size = [adView sizeThatFits:contentFrame.size];
      if (adView.bannerLoaded) {bannerFrame.origin.y = contentFrame.size.height-bannerFrame.size.height;}
      else {bannerFrame.origin.y = contentFrame.size.height;}
      [adView setFrame:bannerFrame];}

Then to handle the callbacks from iAd we need to tell the view to redo its layout if something changes:

- (void)bannerViewDidLoadAd:(ADBannerView *)banner{
[UIView animateWithDuration:0.25 animations:^{
    [self.view setNeedsLayout];
    [self.view layoutIfNeeded];
}];}

- (void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error{
[UIView animateWithDuration:0.25 animations:^{
    [self.view setNeedsLayout];
    [self.view layoutIfNeeded];
}];}

This seems to handle the orientation correctly on both iPad and iPhone except for the test full page ads. However, the screen assume correct orientation after the test ad is dismissed so I am hoping it is all OK.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文