iAd风景奇怪的看法行为

我有一个iAd,显示在主视图的全屏子视图的顶部。 iAd通常以纵向模式工作,我已经将iAd横幅视图的旋转处理为横向模式。 用户在横向模式下轻敲iAd时,会发生此问题。 testing广告以纵向显示,横向显示在电话上,当用户点击x以closuresiAd时,横幅视图及其父视图被推离屏幕。 iAd在纵向模式下正常运行(即点击并closures,导致包含横幅的视图正常显示)。

我已经尝试过的事情:

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

其中调用我用来为纵向和横向模式设置animation旋转的代码。 这个代码没有效果。

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

我不知道这是否解决了所有的问题,但根据这个问题的答案,testing广告只是纵向的,真正的广告会出现在两个方向。

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

ADBannerView与父视图的框架和转换属性混淆,所以您只需在完成后将其重置为原始值(在bannerViewActionDidFinish:bannerViewActionDidFinish:

我还是不明白为什么它没有把它完成后的一切都放回去。 我们不应该这样做。

这也使我疯狂。 只向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的callback,我们需要告诉视图重做其布局,如果有什么改变:

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

除了testing整页广告之外,这似乎在iPad和iPhone上正确处理方向。 但是,在testing广告被解散之后,屏幕会采取正确的方向,所以我希望这一切都可以。