将 ADBannerView 移出屏幕



是的,我已经看到了另一个问题,它们没有帮助。所以我想把iAD横幅从我的视野中移开。它在iPhone上,在纵向视图的屏幕顶部。这是我的代码。我哪里出错了?

//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;
   }
}

更好的是,您可以像这样更改iPhone的"moveBannerViewOffScreen"中的代码

[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];

在"移动横幅视图屏幕上"

 [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];

你不应该需要隐藏相关的代码。此外,您的代码每次都会进一步向上移动横幅视图,或者每次都会进一步向下移动横幅视图,因为您以增量方式应用偏移量。最好每次都手动设置帧:

//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];

相关内容

  • 没有找到相关文章

最新更新