Question

Views in my app are portrait only - my view controllers and the root view controller both ensure that they only rotate to portrait orientations using both shouldAutorotateToInterfaceOrientation: and supportedInterfaceOrientations in order to support both iOS 5 and iOS 6. I've added an iAd banner to a view, and it appears correctly at the top of the screen. When I tap it to see a test ad on the iPad, the test ad appears in lanscape, which I expect - I understand iAds may be in any orientation. But when I close the ad my views are in landscape, both the view with the banner and the view of the root view controller. They rotate back to portrait and stay there when I rotate the device.

How can I prevent iAds from rotating my view, or make my views return to portrait when the iAd closes?

Edit: I've also tried using application:supportedInterfaceOrientationsForWindow: and setting shouldAutoRotate to true - neither solves the problem.

Edit again: I've still had no luck. Here's a project with a fairly minimal view controller implementation that shows the bug I'm experiencing - any help is appreciated!

Was it helpful?

Solution 2

Solved. My secondary view controller had to be a child view controller of the main one.

OTHER TIPS

I would try 2 things. First set the "Supported interface orientations" in your app's Target configuration (Summary).

Then for each view in your interface builder, under the simulated metrics (4 tab on the properties panel) make sure Portrait orientation is selected. If you have "inferred" selected, then it will take the previous screen orientation when it displays itself.

I thought i'd just push an update as i got this fixed finally, this works on iOS 8 and 9, first up register the app to track device orientation.

AppDelegate.m:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

    [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];

    return YES;
}

Now when the advert finishes displaying you can check the device orientation and force it back to portrait.

-(void)bannerViewActionDidFinish:(ADBannerView *)banner{

            UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];

            if (UIDeviceOrientationIsLandscape(orientation)) {

                NSNumber *value = [NSNumber numberWithInt:UIInterfaceOrientationPortrait];
                [[UIDevice currentDevice] setValue:value forKey:@"orientation"];
            }

            //NSLog(@"iAD actions finished");
    }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top