2011-04-27 4 views
2

전체 화면을 포함하는 UITextview가 있습니다. 키보드를 보완하기 위해 다음 핸들러를 추가했습니다.키보드, 방향 및 UITextView

- (void)keyboardWasShown:(NSNotification*)aNotification{ 
    // Resize for the stupid keyboard 
    NSDictionary* info = [aNotification userInfo]; 
    CGSize kbSize = [[info objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size; 

    CGRect rect = _textView.frame; 
    rect.size.height -= kbSize.height; 
    _textView.frame = rect; 

    CGPoint p = [_textView contentOffset]; 
    [_textView setContentOffset:p animated:NO]; 
    [_textView scrollRangeToVisible:NSMakeRange([_textView.text length], 0)]; 
} 

이 방법은 세로 모드에서는 멋지게 작동하지만 가로 모드에서는보기가 완전히 사라집니다. 이 문제를 해결하기위한보다 우아한 해결책이 있습니까? 사과 keyboard management 설명서를 읽었지 만 오리엔테이션 문제는 많지 않습니다.

답변

3

그래서, 내 불행한 솔루션은 내가 생각이

UIInterfaceOrientation o = [self interfaceOrientation]; 
if(o == UIInterfaceOrientationPortrait || o == UIInterfaceOrientationPortraitUpsideDown){ 
    rect.size.height -= kbSize.height; 
}else if(o == UIInterfaceOrientationLandscapeLeft || o == UIInterfaceOrientationLandscapeRight){ 
    rect.size.height -= kbSize.width; 
} 

는이 문제를 해결하는 유일한 방법입니다. 그래도 여전히 우아한 솔루션을 원합니다 :)