Jaume
Jaume

Reputation: 923

iAd doesn't fit width when starts from landscape mode

I am switching and scaling properly iAd on portraid and landscape mode excepts when view starts from landscape mode. In this case, iAd remains at narrow width that corresponds to portraid. Then when rotate the device to portraid and back to landscape, is solved. How to solve it? Thank you.

- (void)viewDidLoad
{   
    //iAd

    adView =[[ADBannerView alloc] initWithFrame:CGRectZero];

    adView.requiredContentSizeIdentifiers = [NSSet setWithObjects: ADBannerContentSizeIdentifierPortrait, ADBannerContentSizeIdentifierLandscape, nil];

    adView.delegate = self;

    [self.view addSubview:adView];

    [super viewDidLoad];
}


- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)orientation duration:(NSTimeInterval)duration {

    if (UIInterfaceOrientationIsPortrait(orientation)) {
        adView.currentContentSizeIdentifier = ADBannerContentSizeIdentifierPortrait;
    } else {
        adView.currentContentSizeIdentifier = ADBannerContentSizeIdentifierLandscape;
    }

}

Upvotes: 1

Views: 636

Answers (1)

sch
sch

Reputation: 27506

You do not tell the adView with which orientation to start, so it starts with the default orientation.

Try adding the following in viewDidLoad:

if (UIInterfaceOrientationIsPortrait([UIDevice currentDevice].orientation)) {
    adView.currentContentSizeIdentifier = ADBannerContentSizeIdentifierPortrait;
} else {
    adView.currentContentSizeIdentifier = ADBannerContentSizeIdentifierLandscape;
}
[self.view addSubview:adView];

Upvotes: 1

Related Questions