【问题标题】:iAd Landscape Strange View BehavioriAd Landscape 奇怪的视图行为
【发布时间】:2011-04-26 02:00:57
【问题描述】:

我有一个 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];
    }
}

这调用了我用来为纵向和横向模式显示旋转动画的代码。此代码无效。

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

【问题讨论】:

  • 您的 animateRotationToLandscape 代码在哪里?
  • @wasabi 你提交你的应用了吗?他们接受了吗?从应用商店下载时,您的广告是否正确显示?

标签: iphone ios iad


【解决方案1】:

我不知道这是否解决了你所有的问题,但是根据this question上的回答,测试广告只是纵向的,真实的广告会在两个方向上展示。

【讨论】:

  • 所以你认为我应该将我的应用程序提交到应用商店并希望这不是部署版本的问题?我无法在应用商店提交之前测试 iAd。
  • @wasabi 你提交你的应用了吗?他们接受了吗?从应用商店下载时,您的广告是否正确显示?
  • @Rookie 是的,接受的答案是正确的。广告在应用商店中以横向方式正常工作。我最终删除了 iAd,因为它们侵入了用户体验。
  • @wasabi 感谢您回复我。非常感谢
【解决方案2】:

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

ADBannerView 与父视图的 frame 和 transform 属性混淆,因此您只需在完成后将它们重置为原始值(在 bannerViewActionDidFinish: 中)。

我仍然不明白为什么它在完成后不把所有东西都放回原处。我们不应该这样做。

【讨论】:

  • 您能提供更多上下文吗?怎么放回去?
【解决方案3】:

这也让我发疯了。只向 iPad 提供横向整页广告,向 iPhone 提供纵向广告,而不这么说是自找麻烦。我放弃了使用 iAdSuite 代码,这导致 iPad 横屏广告即使在设备处于竖屏状态时也会以横屏模式离开屏幕!

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

在头文件中:

#import "iAd/ADBannerView.h"

@property (strong, nonatomic) ADBannerView* adView;

@interface myViewController : UIViewController <ADBannerViewDelegate,

在 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];

然后

-(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 上正确处理方向,但测试整页广告除外。但是,在关闭测试广告后,屏幕会呈现正确的方向,所以我希望一切正常。

【讨论】:

  • 在您的 viewDidLoad 代码中,您在调用 [adView sizeThatFits:contentFrame.size] 后初始化 adView。那时的 adView 不是 nil 吗?
  • self.adView = [[ADBannerView alloc] initWithAdType:ADAdTypeBanner];[self.view addSubview:self.adView]; CGRect contentFrame = self.view.bounds; CGRect bannerFrame = CGRectZero; bannerFrame.size = [self.adView sizeThatFits:contentFrame.size]; bannerFrame.origin.y = contentFrame.size.height-bannerFrame.size.height; [self.adView setFrame:bannerFrame];
  • 抱歉耽搁了!我认为 adView 虽然没有内容,但它是一个 AdBannerView,因此返回一个大小。它似乎工作,我会在它上面运行调试器,看看它在做什么。
猜你喜欢
  • 1970-01-01
  • 2019-01-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-03-01
相关资源
最近更新 更多