Search code examples
iosios6orientationiadautorotate

iOS 6 iAd orientation issues - iAds rotate my portrait only app to landscape and leaves it that way


I have created an iOS6 "Single View" iPhone application.

The application is portrait only.

I added iAds to the application.

I add additional views to the application like this:

         if (self.menuChoiceInstance == nil) {            
                 self.menuChoiceInstance = [[NJDViewControllerMenuChoice alloc] initWithNibName:@"NJDViewControllerMenuChoice" bundle:nil];
                 self.menuChoiceInstance.delegate = self;
         }

         [self.view addSubview:self.menuChoiceInstance.view];

Everything seemed to work fine.

I then added universal/iPad support. Including the following line when I add my subview:

         [self.menuChoiceInstance.view setFrame:CGRectMake(0, 0, self.view.frame.size.width,
                                   self.view.frame.size.height)];

Now I get issues with iAds.

When pressing an iAd on the the rootViewController the iPad rotates to landscape. It then rotates back to portrait on closing the advert.

However pressing an iAd on the iPad on a subview makes the view rotate to landscape, and it stays landscape on closing. This destroys my user interface.

This iPad issue is the main problem, but I now also occasionally see issues with the iPhone view too, which could be related.

The iAd banner at the bottom of the screen showing the test ads sometimes has giant text and icons within it, making them overlap each other and impossible to read. Pressing the iAd rotates the phone to landscape (again in a portrait only app), yet the iAd shows the advert as if it is still portrait, with stretched content that goes off the bottom of the screen.


Solution

  • I believe the issue was caused by the fact that I was adding subviews onto my current view, rather than switching views.

    I have changed the code that adds a subview from:

    [self.view addSubview:self.statsInstance.view];
    

    to code that presents a view.

    [self presentViewController: self.settingsInstance animated:YES completion:nil];
    

    This seems to have resolved my issue, as well as some other issues with iAd delegation methods (bannerViewActionDidFinish was called straight after the ad loaded.)