ipAd不适合iPad横向模式

时间:2012-02-18 11:43:49

标签: iphone objective-c ios xcode cocoa-touch

我也试图在两种模式,风景和肖像中适应iAd但在横向模式下无法达到它,横幅保持相同的比例。谢谢,这是我的代码:

- (void)bannerViewDidLoadAd:(ADBannerView *)banner {

    if (!self.bannerIsVisible) {

        [UIView beginAnimations:@"animateOn" context:NULL];
        adView.frame = CGRectOffset(adView.frame, 0, -adView.frame.size.height);
        [UIView commitAnimations];
        self.bannerIsVisible = YES;

    }

}

- (void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error {

    if (!self.bannerIsVisible) {

        [UIView beginAnimations:@"animateOff" context:NULL];
        adView.frame = CGRectOffset(adView.frame, 0, adView.frame.size.height);
        [UIView commitAnimations];
        self.bannerIsVisible = NO;
    }

}

- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)orientation duration:(NSTimeInterval)duration {

    if (UIInterfaceOrientationIsPortrait(orientation)) {
        adView.currentContentSizeIdentifier = ADBannerContentSizeIdentifierPortrait;
    } else {
        adView.currentContentSizeIdentifier = ADBannerContentSizeIdentifierLandscape;
    }

}

- (void)viewDidLoad
{
    self.bannerIsVisible = NO;

    adView =[[ADBannerView alloc] initWithFrame:CGRectZero];
    adView.currentContentSizeIdentifier = ADBannerContentSizeIdentifierPortrait;

    adView.delegate = self;

    [self.view addSubview:adView];

    [super viewDidLoad];
}

1 个答案:

答案 0 :(得分:1)

在此official Apple link,您可以找到您要查找的代码。

在该文档中,有一节称为:动态更改横幅尺寸

在那一节Apple专门说,为了能够动态地改变横幅的大小,你需要这行代码:

self.bannerView.requiredContentSizeIdentifiers = [NSSet setWithObjects: 
           ADBannerContentSizeIdentifierPortrait, 
                  ADBannerContentSizeIdentifierLandscape, nil]; 

我在你发布的代码上看不到它。