2012-02-20 11 views
0

横向きまたは縦向きのときにiAdサイズを制御しようとしています。問題は、デバイスが肖像画上にあるときにそれが風景にあると伝えることです!どのようにそれを処理するには?ありがとうございますiOSがポートレートのときに横向きを返す

- (void)viewDidLoad 
{ 

    //iAd 

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

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

    adView.delegate = self; 

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

    [self.view addSubview:adView]; 

    [super viewDidLoad]; 
} 

答えて

1

ほとんどの場合、ここでは常に[self interfaceOrientation]を使用します。

orientationは、ノートthe docs動作しない理由について:オリエンテーション通知がbeginGeneratingDeviceOrientationNotificationsを呼び出すことによって有効にされていない限り、このプロパティの値は常に0を返す

を。

+0

これは、ありがとうございます! – Jaume

0

ポートレートのみを認識するように設定されている場合は、ランドスケープ上にあるか、単にポートレートではないことを伝えていますか?このスレッドで説明したように、シミュレータがnilを返している可能性があります。UIDevice currentDevice's "orientation" always null シミュレータまたはデバイスを使用していますか?

関連する問題