2

アプリを縦向きだけでなく横向きでも機能させようとしています。すべてのビューコントローラーに適切なメソッドがインストールされており、iPad シミュレーターが回転するとこのコードがトリガーされますが、常にポートレートがトリガーされます。ランドスケープ IF 句がトリガーされることはありません。私は何が間違っているのでしょうか?

-(void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)InterfaceOrientation {
NSLog(@"******* ROTATING ******");
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
{
    if(UIInterfaceOrientationIsLandscape(self.interfaceOrientation)) {

        NSLog(@"ROTATING View Landscape ******");

    } else    if(UIInterfaceOrientationIsPortrait(self.interfaceOrientation)) {

        NSLog(@"ROTATING View Portrait ******");

    }
} 

}

4

4 に答える 4

5

デバイスとインターフェイスの向きは別物に見えます。Apple のサイトで、UIDeviceOrientation を使用してこれを行う方法を見つけました。このテストを使用すると、シミュレーターと iPad デバイスを回転させると適切なトリガーが得られます。

    UIDeviceOrientation deviceOrientation = [UIDevice currentDevice].orientation;

if (UIDeviceOrientationIsLandscape(deviceOrientation))

{


}

else if (deviceOrientation == UIDeviceOrientationPortrait)

{

}    
于 2011-03-24T01:55:50.517 に答える
4

iPhone/iPad の現在のデバイスの向きを検出する最も信頼できる方法はstatusBarOrientation、次のようにプロパティを使用することです。

UIInterfaceOrientation currentOrientation = 
    [UIApplication sharedApplication].statusBarOrientation;

の代わりにそれを使用するとself.interfaceOrientation、コードは機能しますか?

于 2011-03-23T11:58:30.920 に答える