实现iAd的有效方式

时间:2014-12-18 07:24:29

标签: objective-c iad uiviewanimation adbannerview

我使用一种简单的方法设置iAd ..但每次iAd动画时,我的SpriteKit游戏开始滞后。我想知道是否有更有效的方式?

- (void)bannerViewDidLoadAd:(ADBannerView *)banner {
[UIView animateWithDuration:0.1 animations:^(void) {
    banner.alpha = 1;
}];
}
- (void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error {
    [UIView animateWithDuration:0.1 animations:^(void){
        banner.alpha = 0;
    }];
}

1 个答案:

答案 0 :(得分:0)

以下是我在最近的应用程序中实现iAd的方法,一切都对我有用..没有滞后,没有。试试这个。

- (void)viewDidLoad {
          _bannerView = [[ADBannerView alloc] initWithFrame:CGRectZero];
          _bannerView.delegate = self;
          [self.view addSubview:_bannerView];
          [self layoutAnimated:NO];
}

- (void)layoutAnimated:(BOOL)animated
{
      CGRect contentFrame = self.view.bounds;
      CGRect bannerFrame = _bannerView.frame;
      if (_bannerView.bannerLoaded)
      {
           contentFrame.size.height -= _bannerView.frame.size.height;
           bannerFrame.origin.y = contentFrame.size.height;
      } else {

           contentFrame.size.height = self.view.bounds.size.height;
           bannerFrame.origin.y = contentFrame.size.height;

       }

      [UIView animateWithDuration:animated ? 0.25 : 0.0 animations:^{
          self.movieDetailTableView.frame = contentFrame;
          [self.movieDetailTableView layoutIfNeeded];
          _bannerView.frame = bannerFrame;
       }];
}
#pragma mark - Delegates

- (void)bannerViewDidLoadAd:(ADBannerView *)banner
{
     [self layoutAnimated:YES];
}
- (BOOL)bannerViewActionShouldBegin:(ADBannerView *)banner willLeaveApplication:(BOOL)willLeave
{
     NSLog(@"Banner view is beginning an ad action");
     BOOL shouldExecuteAction = YES; // your app implements this method
     if (!willLeave && shouldExecuteAction)
     {
        // insert code here to suspend any services that might conflict with the advertisement
     }
     return shouldExecuteAction;
 }

 - (void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error
 {
     [self layoutAnimated:YES];
 }