2011-04-26 58 views
8

我有一个iAd,它显示在主视图的全屏子视图的顶部。 iAd通常以纵向模式工作,我已将iAd横幅视图的旋转处理为横向模式。用户在横向模式下轻敲iAd时会发生此问题。测试广告以纵向显示,横向显示在手机上,当用户点击x以关闭iAd时,横幅视图及其父视图将被推出屏幕外。 iAd在纵向模式下正常运行(即点击并关闭它会导致包含横幅的视图正常显示)。iAd Landscape奇异视图行为

事情我已经尝试:

- (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]; 
    } 
} 

其中要求,我用动画显示旋转为纵向和横向模式的代码。此代码无效。

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

+0

你的animateRotationToLandscape代码在哪里? – 2012-02-24 01:59:22

+0

@wasabi你提交你的应用程序?他们接受了吗?从应用商店下载广告时,您的广告是否能正确显示 – 4GetFullOf 2014-03-16 16:24:28

回答

5

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

+0

所以你认为我应该将应用程序提交给应用程序商店,并希望这不是部署版本的问题?在应用商店提交之前,我无法测试iAd。 – wasabi 2011-04-27 16:52:39

+0

@wasabi你提交你的应用程序?他们接受了吗?从应用商店下载广告时,您的广告是否能正确显示 – 4GetFullOf 2014-03-16 16:21:43

+2

@Rookie是接受的答案是正确的。广告在应用商店中以横向方向正确工作。我最终删除了iAds,因为它们侵入UX。 – wasabi 2014-03-18 20:30:51

0

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

ADBannerView与父视图的框架和变换属性混淆,因此您只需在完成后将它们重置为其原始值(位于bannerViewActionDidFinish:)。

我还是不明白为什么它没有按照它完成后的方式放回所有东西。我们不应该这样做。

+0

你能否把更多的上下文?如何把它放回去? – ColdSteel 2015-04-18 22:31:09

0

这也使我疯了。只向iPad提供横向全页广告,并向iPhone提供纵向广告,而不是这么说就是要求麻烦。我放弃使用iAdSuite代码,导致横向iPad广告将屏幕留在横向,即使设备处于纵向状态!

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

在头文件:

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

然后

#import "iAd/ADBannerView.h" 

@property (strong, nonatomic) ADBannerView* adView; 

@interface myViewController : UIViewController <ADBannerViewDelegate, 

-(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上正确处理方向。然而,在测试广告被解雇后,屏幕会采取正确的方向,所以我希望这一切都可以。

+0

在viewDidLoad的代码中,您在调用[adView sizeThatFits:contentFrame.size]后正在初始化adView。 adView目前是否为零? – ldanilek 2014-10-08 18:43:01

+0

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]; – ldanilek 2014-10-08 18:47:33

+0

对不起,延迟!我认为adView虽然没有内容,但却是AdBannerView,因此会返回大小。它似乎工作,我会运行调试器在某个时间,看看它是什么。 – Tim 2015-04-09 16:01:55