2010-12-12 6 views
19

こちらの質問はこちらUIDeviceOrientationFaceUpとUIDeviceOrientationFaceDownをどのように処理するのですか?

私は向きを検出:すべての罰金とダンディであると私は

if (orientation == UIDeviceOrientationPortrait || orientation == UIDeviceOrientationPortraitUpsideDown)

と他{で報告された向きに応じて、私のテキストフィールドとラベルの位置を変更

UIInterfaceOrientation orientation = [[UIDevice currentDevice] orientation];

}他のすべての場合

私が最近発見した問題がUIDeviceOrientationFaceUpまたはUIDeviceOrientationFaceDownと報告されたときです。この状況にどうやって対処するのですか?ポートレートまたはランドスケープでUIDeviceOrientationFaceUpUIDeviceOrientationFaceDownが発生しているかどうかを確認するにはどうすればよいですか?私は、デバイスが上下に向かっていることを知っていますが、すべてをポートレートまたはランドスケープに配置する必要があるかどうかはわかりません。

ありがとうございました!

答えて

33

Appleは、ビューのレイアウトにデバイスの向きを使用しないことを推奨しています。代わりに、各ビューコントローラはinterfaceOrientationプロパティを持ち、UIApplicationstatusBarOrientationプロパティを持ち、どちらもビューレイアウトに適したインターフェイスの向きを返します。

変更を監視するには、willRotateToInterfaceOrientation:duration:のようなUIViewControllerメソッドが呼び出され、UIApplicationWillChangeStatusBarOrientationNotificationなどの通知が送信され、インターフェイスの向きが変更されたときに通知されます。

+0

ありがとう、これは有望そうです。私は見てみる – TrekOnTV2017

+0

これは正解です.UIDeviceのオリエンテーションレスポンス(ブログの示唆しているように)がUIViewControllerのinterfaceOrientationを聞いているほど良くはありません。よくやった。 – Jessedc

+0

私はこの答えもよく似ています。 caprica13、これを正しいとマークできますか? –

4

このブログの投稿はこちら:http://blogs.remobjects.com/blogs/mh/2010/06/29/p1685は本当にうまく説明しています。

+0

完璧!私は変更を加え、すべてが今すぐうまくいくようです。ありがとうございました。 – TrekOnTV2017

+0

それは、ウッキーのテーマは私に頭痛を与える、gah – Alex

+0

ハハハは、AppleのObjective-C/frameworksのドキュメンテーションがそのように見えるか想像してみてください! –

-1

私は同じ問題を抱えている

[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications]。

この方法では、7つの可能なデバイスの位置状態の通知を生成します。

UIDeviceOrientationPortrait 
UIDeviceOrientationPortraitUpsideDown 
UIDeviceOrientationLandscapeLeft 
UIDeviceOrientationLandscapeRight 
UIDeviceOrientationFaceUp 
UIDeviceOrientationFaceDown 
UIDeviceOrientationUnknown 

をしかし、私は唯一のも、これは(コードが付属して)この問題を解決するための私のアプローチで、最初の4を必要とする: How to handle UIDeviceOrientation for manage views layouts

0

少し遅れて、うまくいけば、それはあるものを助けるだろう。 iOS 6.0以降については

1)が回転通知を受け取るためにあなたのビューのセットアップ中にこのコードを設定します。

// Set Listener to receive orientation notifications from the device 
    [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications]; 
    [[NSNotificationCenter defaultCenter] addObserver:self 
              selector:@selector(detectOrientation) 
               name:UIDeviceOrientationDidChangeNotification 
              object:nil]; 

2)回転の後に通知をキャッチするために、このコードを設定します。

-(void)detectOrientation{  
    switch ([[UIDevice currentDevice] orientation]) { 
    case UIDeviceOrientationFaceDown:{ 
     NSLog(@"UIDeviceOrientationFaceDown"); 
     break; 
    } 
    case UIDeviceOrientationFaceUp:{ 
     NSLog(@"UIDeviceOrientationFaceUp"); 
     break; 
    } 
    case UIDeviceOrientationLandscapeLeft:{ 
     NSLog(@"UIDeviceOrientationLandscapeLeft"); 
     break; 
    } 
    case UIDeviceOrientationLandscapeRight:{ 
     NSLog(@"UIDeviceOrientationLandscapeRight"); 
     break; 
    } 
    case UIDeviceOrientationPortrait:{ 
     NSLog(@"UIDeviceOrientationPortrait"); 
     break; 
    } 
    case UIDeviceOrientationPortraitUpsideDown:{ 
     NSLog(@"UIDeviceOrientationPortraitUpsideDown"); 
     break; 
    } 
    case UIDeviceOrientationUnknown:{ 
     NSLog(@"UIDeviceOrientationUnknown"); 
     break; 
    } 
    default:{ 
     break; 
    } 
    } 

} 
関連する問題