0

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;
   }
}
Mehul Mistri
  • 15,037
  • 14
  • 70
  • 94
Jason
  • 650
  • 2
  • 10
  • 33
  • I think you can call setFrame property only when a view is Loaded or any of its delegate . did you tried with addSubview – Kunal Balani Jun 22 '12 at 05:21
  • The view is loaded, this is for when there is an error displaying the ad, because of network outage etc.. – Jason Jun 22 '12 at 06:02

3 Answers3

1

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];
Madhumitha
  • 3,794
  • 8
  • 30
  • 45
  • Your cgRectMake should be CGRectMake. No error that way.Thanks for your help! – Jason Jun 23 '12 at 14:00
  • These numbers are hard coded. I gave an answer below that is more flexible. I also explained why the original solution did not work. – Paul de Lange Jun 25 '12 at 09:36
0

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); 
Paul de Lange
  • 10,613
  • 10
  • 41
  • 56
  • Actually apple says to hide the banner until there is an ad to display. Or hide the banner if no ad is able to diplay bc of network issues. – Jason Jun 23 '12 at 14:01
  • [https://developer.apple.com/library/ios/#documentation/UserExperience/Conceptual/iAd_Guide/WorkingwithBannerViews/WorkingwithBannerViews.html#//apple_ref/doc/uid/TP40009881-CH4-SW10] – Jason Jun 25 '12 at 11:52
  • Ok thanks, I see where you got the idea. It is a little bit ambiguous, but I don't think you need to set the hidden property. In fact moving the view off the screen is probably what they mean by "your application must hide the banner view". – Paul de Lange Jun 25 '12 at 12:01
  • Oh I see what you mean, yes, I just want to move the view off screen, not hide it. – Jason Jun 26 '12 at 02:52
  • Your code doesn't animate the banner into the view, could you do that while still be "flexible"? Also, how would I hide the banner is the app entered background? Could you also explain what makes your code more flexible? I would like to know as other new programmers would too. Thanks! – Jason Jun 26 '12 at 03:00
  • It depends how you want to animate it. You have the old animation wrappers ([UIView beginAnimations:context:] etc.) like you see in the other answer or you have the newer block animations ([UIView animateWithDuration:animations:]). You can use either of these methods. To find examples you only need to search the net or the Apple sample code and you should have one in a few minutes. You don't need to hide the banner when the app enters the background. – Paul de Lange Jun 26 '12 at 06:03
0

another simple answer : [myBannerView1 setAlpha:0];

Zen Of Kursat
  • 2,672
  • 1
  • 31
  • 47