8
votes

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.

3
Where is your animateRotationToLandscape code?james_womack
@wasabi have you submitting your app? did they accept it? are your ads displaying correctly when downloaded from app store?4GetFullOf

3 Answers

5
votes

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.

0
votes

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.

0
votes

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.