从横向模式启动时,iAd不适合宽度

时间:2012-02-18 18:35:44

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

我正在切换和缩放iAd在portraid和横向模式下,当视图从横向模式开始时除外。在这种情况下,iAd保持窄宽度,对应于portraid。然后将设备旋转到portraid并返回横向时,解决了。怎么解决?谢谢。

- (void)viewDidLoad
{   
    //iAd

    adView =[[ADBannerView alloc] initWithFrame:CGRectZero];

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

    adView.delegate = self;

    [self.view addSubview:adView];

    [super viewDidLoad];
}


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

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

}

1 个答案:

答案 0 :(得分:1)

您没有告诉adView以哪个方向开始,因此它以默认方向开始。

尝试在viewDidLoad中添加以下内容:

if (UIInterfaceOrientationIsPortrait([UIDevice currentDevice].orientation)) {
    adView.currentContentSizeIdentifier = ADBannerContentSizeIdentifierPortrait;
} else {
    adView.currentContentSizeIdentifier = ADBannerContentSizeIdentifierLandscape;
}
[self.view addSubview:adView];