简体   繁体   中英

Move ADBannerView off screen?

Yes, I've seen the other question and they are of no help. So I want to move the iAD banner off of my view. It's on the iphone, at the top of the screen on portrait view. Here is my code. Where am I going wrong here?

//Move the banner off the screen.
- (void)moveBannerViewOffScreen
{
   if (self.bannerView.isHidden == NO)
   {
       [UIView beginAnimations:@"animateAdBannerOff" context:NULL];
       bannerView.frame = CGRectOffset(bannerView.frame, 0, bannerView.frame.size.height);
       [UIView commitAnimations];
       self.bannerView.hidden = YES;
   }    
}

//Move the banner on the screen.
- (void)moveBannerOnScreen
{
   if (self.bannerView.isHidden ==YES)
   {
       [UIView beginAnimations:@"animateAdBannerOn" context:NULL];
       bannerView.frame = CGRectOffset(bannerView.frame, 0, -bannerView.frame.size.height);
       [UIView commitAnimations];
       self.bannerView.hidden = NO;
   }
}

Better you can change code in "moveBannerViewOffScreen" for iphone like this

[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1.0];
[UIView setAnimationTransition:UIViewAnimationTransitionNone forView:bannerView cache:YES];
bannerView.frame = cgRectMake(0,-50,50,320);
[UIView commitAnimations];

in"moveBannerViewOnScreen"

 [UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1.0];
[UIView setAnimationTransition:UIViewAnimationTransitionNone forView:bannerView cache:YES];
bannerView.frame = cgRectMake(0,0,50,320);
[UIView commitAnimations];

You shouldn't need the hiding related code. Also your code will move the banner view up further each time or down further each time because you applying an offset incrementally. It is better for you to manually set the frame each time:

//Offscreen frame
bannerView.frame = CGRectMake(0, -bannerView.frame.size.height, bannerView.frame.size.width, bannerView.frame.size.height);

//Onscreen frame
bannerView.frame = CGRectMake(0, 0, bannerView.frame.size.width, bannerView.frame.size.height); 

另一个简单的答案:[myBannerView1 setAlpha:0];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM