为什么我的ipAd横幅没有显示?

时间:2011-11-04 20:05:18

标签: objective-c ios iad

- (void)viewDidLoad
{

    adView = [[ADBannerView alloc] initWithFrame:CGRectZero];
    adView.requiredContentSizeIdentifiers = [NSSet setWithObject:ADBannerContentSizeIdentifierPortrait];
    adView.currentContentSizeIdentifier = ADBannerContentSizeIdentifierPortrait;
    CGRect adFrame = adView.frame;
    adFrame.origin.y = self.view.frame.size.height-adView.frame.size.height;
    adView.frame = adFrame;
    [self.view addSubview:adView];

}


- (void)bannerViewDidLoadAd:(ADBannerView *)banner
{
    if (!self.bannerIsVisible)
    {
        self.bannerIsVisible = YES;
    }
}

- (void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error
{
    if (self.bannerIsVisible)
    {

        self.bannerIsVisible = NO;
    }

2 个答案:

答案 0 :(得分:2)

有四件事。首先,您应该在viewDidLoad方法中将横幅放在屏幕上,因为它在您首次启动时只显示一个空框架,并且很可能因此而被拒绝。

其次,您正在错误地设置横幅视图。我认为框架仍然是CGZero。第三,您没有设置bannerView的委托。请尝试以下方法:

-(void)viewDidLoad{
    CGRect frame=CGRectZero;
    frame.size = [ADBannerView sizeFromBannerContentSizeIdentifier:ADBannerContentSizeIdentifierPortrait];
    // Place frame at the bottom edge of the screen out of sight
    frame.origin = CGPointMake(0.0, CGRectGetMaxY(self.view.bounds));

    // Now to create and configure the banner view
    ADBannerView *adView = [[ADBannerView alloc] initWithFrame:frame];
    adView.requiredContentSizeIdentifiers = [NSSet setWithObject:ADBannerContentSizeIdentifierPortrait];
    // Set the delegate to self, so that we are notified of ad responses
    adView.delegate = self;
    [self.view addSubview: adView];
}

第四,在bannerViewDidLoadAd:方法中,您没有将横幅广告设置为动画。试试这个:

- (void)bannerViewDidLoadAd:(ADBannerView *)banner
{
    // Get a brand new frame
    CGRect newFrame=CGRectZero;
    CGPoint frameOrigin=CGPointZero;
    // Set the origin
    frameOrigin=CGPointMake(0.0, CGRectGetMaxY(self.view.bounds));
    newFrame.origin=frameOrigin;

    // Set the size
    newFrame.size=[ADBannerView sizeFromBannerContentSizeIdentifier:ADBannerContentSizeIdentifierPortrait];

    CGFloat bannerHeight = newFrame.size.height;
    CGFloat bannerOffset=0.0;

    // Determine where the new frame should be
    if (!self.bannerIsVisible)
    {   
        // It should be visible, raise it up
        bannerOffset=-bannerHeight;
    }

    CGRect offSetRect=CGRectOffset(newFrame,0.0f,bannerOffset);
        [UIView animateWithDuration:0.2
                         animations:^{banner.view.frame=offSetRect}
                         completion:^(BOOL finished){
                             if (bannerOffSet<0){
                               self.bannerIsVisible=YES;
                             }else{
                               self.bannerIsVisible=NO;
                             }
                         }
        ]; 

}

当然,如果横幅应该位于屏幕的顶部,您可以弄清楚需要修改的内容,但这会让您朝着正确的方向前进。

祝你好运

答案 1 :(得分:0)

通过阅读您的问题不确定,但请注意Apple模拟iAds无法使用。有时您需要在示例广告出现之前尝试多次。