tags:

views:

19

answers:

1

I have added a banner view for implementing iAd in the bottom of the screen. But when running on the simulator the banner view is slightly above the frame fixed for it. It appears as a transparent strip and is not selectable. After sometime it automatically comes to the bottom as a black strip saying Test Advertisement.

I want the banner View to stick to the bottom and not animate.

Here is my code. The adView declaration code:

adView = [[[ADBannerView alloc] initWithFrame:CGRectOffset(CGRectZero, 0, 350)] autorelease];
adView.frame = CGRectMake(0,340,320,25);
adView.requiredContentSizeIdentifiers = [NSSet setWithObject:ADBannerContentSizeIdentifier320x50];
adView.currentContentSizeIdentifier = ADBannerContentSizeIdentifier320x50;
adView.autoresizingMask = UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleRightMargin;
adView.tag = 111;
[self.navigationController.view addSubview:adView];
adView.delegate = self;
self.bannerIsVisible = NO;
adView.hidden = YES;

Here are the delegate methods.

- (void)bannerViewDidLoadAd:(ADBannerView *)banner
{
    if (!self.bannerIsVisible)  {

        [UIView beginAnimations:@"animateAdBannerOff" context:NULL];

        // banner is invisible now and moved out of the screen on 50 px
        banner.frame = CGRectOffset(banner.frame, 0, 50);
        [UIView commitAnimations];
        self.bannerIsVisible = YES;
    }
}

// When iAd is not availale on the banner
- (void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error
{
    if (self.bannerIsVisible) {

        [UIView beginAnimations:@"animateAdBannerOff" context:NULL];        
        // banner is visible and we move it out of the screen, due to connection issue
        banner.frame = CGRectOffset(banner.frame, 0, 520);
        [UIView commitAnimations];      
        self.bannerIsVisible = NO;
    }
}

I am not able to understand the problem. Kindly help.

A: 

First. When the main view is loaded how are the objects placed in it initially? I always place them in right positions inside viewDidLoad method. So place your banner below the bottom of the main view making sure that

myBannerFrame.origin.x = 0;
myBannerFrame.origin.y = mainView.frame.size.height;
[myBanner setFrame:myBannerFrame]; // no need for animation here! 

Also viewDidLoad is a good place to set your flag self.bannerIsVisible to FALSE.

Second. Do not use fixed pixel values like here

banner.frame = CGRectOffset(banner.frame, 0, 50);

instead of 50 you better put banner.frame.size.height This will help you to avoid many errors and misalignments.

Sergei Lost
i have later on put the banner view directly through the interface builder. But it seems to shift position after some time.
Bismita