English 中文(简体)
iAd left white blank screen after closed
原标题:

I got a problem to integrate iAd in my iPhone apps -- the banner ad is fine when it expends (see http://www.clingmarks.com/iAd1.png and http://www.clingmarks.com/iAd2.png), however, when I close it, it left a white blank screen (see http://www.clingmarks.com/iAd3.png). I couldn t figure out why. Here is how I integrate the ad:

Because I need to support other ads for lower version of iPhone OSes, I add a container view at the top of the apps, whose view controller is AdViewController. When the view is loaded, I create a AdBannerView programmatically and add it as a subview to the AdViewController.view. Here is the code in the viewDidLoad method:

Class adClass = (NSClassFromString(@"ADBannerView"));
if (adClass != nil) {
    iAdView = [[ADBannerView alloc] initWithFrame:CGRectZero];
    iAdView.frame = CGRectOffset(iAdView.frame, 0, -50);
    iAdView.requiredContentSizeIdentifiers = [NSSet setWithObject:ADBannerContentSizeIdentifier320x50];
    iAdView.currentContentSizeIdentifier = ADBannerContentSizeIdentifier320x50;
    iAdView.delegate = self;
    iadViewIsVisible = NO;
    [self.view addSubview:iAdView];
} else {
       // init google adsense
    }

Following are the delegate methods:

enter code here
- (void)bannerViewDidLoadAd:(ADBannerView *)banner {
if (!iadViewIsVisible) {
    [UIView beginAnimations:@"animateAdBannerOn" context:NULL];
    // banner is invisible now and moved out of the screen on 50 px
    banner.frame = CGRectOffset(banner.frame, 0, 50);
    [UIView commitAnimations];
    iadViewIsVisible = YES;
}
}

- (void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error {
if (iadViewIsVisible) {
    [UIView beginAnimations:@"animateAdBannerOff" context:NULL];
    // banner is visible and we move it out of the screen, due to connection issue
    banner.frame = CGRectOffset(banner.frame, 0, -50);
    [UIView commitAnimations];
    iadViewIsVisible = NO;
}
}
最佳回答

Eventually I figured it out myself. It turns out the ADBannerView s parent view must be a fullscreen view. I my case above, I added AdBannerView to my adView, which is a view with size 320x50. When I changed its parent view to a fullscreen view, everything works. I am not sure if this is a bug in iAd, but certainly something tricky.

问题回答

When the banner finishes, it moves itself to the top of the screen even if that means having a negative y coordinate. I center the banner when it finishes. In my case there is a view controller for just the banner, so it is only full screen when the ad is clicked.

-(void) bannerViewActionDidFinish:(UIView *)inBanner {
    CGRect                      frame = [inBanner frame];

    frame.origin.x = frame.size.width * 0.5;
    frame.origin.y = frame.size.height * 0.5;

    [inBanner setCenter:frame.origin];
}

Hey David! I know what you mean, I m also using an own AdvertisementViewController which calls different ad networks.

So iAd is not in a full screen view but inside a 320x50 view.

Simply do this:

-(void) bannerViewActionDidFinish:(ADBannerView *)inBanner {

[self.view setFrame:CGRectMake(0.0f, 0.0f, 320.0f, 50.0f)];

}

So the outer view container (self.view) is resized to its original size. iAd is resizing it to fullscreen for displaying the ad when an iAd is shown.





相关问题
Code sign Error

I have created a new iPhone application.I have two mach machines. I have created the certificate for running application in iPhone in one mac. Can I use the other mac for running the application in ...

ABPersonViewController Usage for displaying contact

Created a View based Project and added a contact to the AddressBook using ABAddressBookRef,ABRecordRef now i wanted to display the added contact ABPersonViewController is the method but how to use in ...

将音频Clips从Peter改为服务器

我不禁要问,那里是否有任何实例表明从Peit向服务器发送音响。 I m不关心电话或SIP风格的解决办法,只是一个简单的袖珍流程......

• 如何将搜查线重新定位?

我正试图把图像放在搜索条左边。 但是,问题始于这里,搜索条线不能重新布署。

热门标签