copenndthagen
copenndthagen

Reputation: 50742

Rotate iAd with orientation change (iPhone/iPad)

I have a Universal app (iPhone/iPad) which has an iAd displayed at the bottom of the view.

I use the following code to position it on view load;

- (void)viewDidLoad {

    bannerIsVisible = YES;
ADBannerView *adView = [[ADBannerView alloc] initWithFrame:CGRectZero];

    float origin_y;
    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) 
        origin_y = 360.0;
    else
        origin_y = self.view.frame.size.height;

    adView.frame = CGRectMake(0.0,origin_y, adView.frame.size.width, adView.frame.size.height);
adView.delegate = self;

    if ( &ADBannerContentSizeIdentifierPortrait != NULL ) {
        adView.requiredContentSizeIdentifiers = [NSSet setWithObject:ADBannerContentSizeIdentifierPortrait];
        adView.currentContentSizeIdentifier = ADBannerContentSizeIdentifierPortrait;

else  {
        adView.requiredContentSizeIdentifiers  = [NSSet  setWithObject:ADBannerContentSizeIdentifier320x50];
        adView.currentContentSizeIdentifier  = ADBannerContentSizeIdentifier320x50;
    }

    [self.view  bringSubviewToFront:adView];
[webView  addSubview:adView];

    [super  viewDidLoad];
}

Now I want to support all 4 orienations i.e. the iAd should move to the bottom on all the 4 orienations

So my question is simply how do I update the following code to support the same;

(BOOL)shouldAutorotateToInterfaceOrientationUIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations
    return  YES;
}

Please note 2 things; 1. I need the same code to work on both iPhone/iPad 2. I am ready to update the fixed value of origin_y from 360.0 to whatever you can suggest.

Thank you.

Upvotes: 1

Views: 1549

Answers (1)

Niko
Niko

Reputation: 2543

You can work with the autoResizingMask, like this :

[adView setAutoresizingMask:UIViewAutoresizingFlexibleRightMargin  
 |  UIViewAutoresizingFlexibleTopMargin    
 |  UIViewAutoresizingFlexibleHeight ]; 

Without the UIViewAutoresizingFlexibleBottomMargin, this means that the object will keep the same margin from the bottom of the screen in every device orientation, so stay at the bottom in your case.

Upvotes: 2

Related Questions