4

ユーザーがiPadを横向きモードで保持している場合、キーボードのフレームオフセットを決定しています。横向きモードでコンテンツを追加してからiPadを表面に平らに設定すると、オフセットを適切に設定できないことがわかりました。以下のコードを使用してオフセットを設定しています。

if ([[UIDevice currentDevice] orientation] == UIDeviceOrientationLandscapeLeft || [[UIDevice currentDevice] orientation] == UIDeviceOrientationLandscapeRight) {
    tableView.frame = CGRectMake(0,0,tableView.frame.size.width, tableView.frame.size.height-keyboardsize.height);
}

私がチェックできるUIDeviceOrientationsは次のとおりです。

typedef enum {
   UIDeviceOrientationUnknown,
   UIDeviceOrientationPortrait,
   UIDeviceOrientationPortraitUpsideDown,
   UIDeviceOrientationLandscapeLeft,
   UIDeviceOrientationLandscapeRight,
   UIDeviceOrientationFaceUp,
   UIDeviceOrientationFaceDown
} UIDeviceOrientation;

(ソース:http ://developer.apple.com/library/ios/#documentation/uikit/reference/UIDevice_Class/Reference/UIDevice.html )

ユーザーがアプリを横向き(UIDeviceOrientationLandscapeLeftまたはUIDeviceOrientationLandscapeRight)に持っているかどうかを確認/確認してから、デバイスを下に置く(そうする必要がありますUIDeviceOrientationFaceUp)方法はありますか?

4

1 に答える 1

4

関心があるのは、デバイスの向きではなく、インターフェイスの向きです。使用してみてください(ビューコントローラはself.interfaceOrientationどこにありますか)。selfこれはからも取得できます[[UIApplication sharedApplication] statusBarOrientation]

そうは言っても、キーボードがどこにあるかを見つけるためにインターフェイスの向きを使用するべきではないでしょう。キーボードは、表示されて移動すると、位置情報を含む通知を生成します。UIKeyboardWillShowNotificationとを見てくださいUIKeyboardWillChangeFrameNotification。userInfoディクショナリのキーUIKeyboardFrameBeginUserInfoKeyUIKeyboardFrameEndUserInfoKeyキーの下に位置情報があり、キーボードの位置を示します。

于 2012-12-20T01:43:13.057 に答える