3

사용자가 iPad를 가로 모드로 잡고있는 경우 키보드의 프레임 오프셋을 결정합니다. 가로 모드에서 콘텐츠를 추가하고 표면에 iPad를 평평하게 놓으면 옵셋을 올바르게 설정할 수 없습니다. 내가 오프셋 설정 아래 코드를 사용하고 있습니다 : 내가 확인할 수 있습니다기기를 표면에 설치 한 후 앱 UI가 가로 방향인지 확인할 수 있습니까?

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

관심있는 내용은 기기 방향이 아니라 인터페이스 방향입니다. self.interfaceOrientation을 사용해보십시오 (여기에서 self은보기 컨트롤러입니다). [[UIApplication sharedApplication] statusBarOrientation]에서 가져올 수도 있습니다.

키보드의 위치를 ​​알아 내기 위해 인터페이스 방향을 전혀 사용해서는 안됩니다. 키보드는 위치 정보가 포함되어 나타나고 이동하면 알림을 생성합니다. UIKeyboardWillShowNotificationUIKeyboardWillChangeFrameNotification을 살펴보십시오. 키보드의 위치를 ​​알려주는 UIKeyboardFrameBeginUserInfoKeyUIKeyboardFrameEndUserInfoKey 키 아래 userInfo 사전에 위치 정보가 있습니다.

+0

내 문제를 해결했습니다. – propstm

관련 문제