2012-07-17 2 views
0

저는 uitextfields 및 uitextviews를 가지고있는 ipad에 꽤 긴 형식을 가지고 있습니다. 키보드 알림을 사용하여 키보드가 uitextfield를 숨길 때 위로 스크롤 할 수 있습니다. 하지만 uitextview가 활성 상태가되고 키보드 아래에 있으면 커서가 깜박이는 것을 볼 수있을 정도로 슬라이드됩니다. 이것은 정상적인 행동입니까? 어떻게 전체 uitextview를 편집 할 때 볼 수 있도록 전체 uitextview를 위쪽으로 스크롤 할 수 있습니까? 여기 ipad 키보드가 uitextView를 숨 깁니다.

은 UITextView

CGRect activeField; 

- (void)textViewDidBeginEditing:(UITextView *)textView 
{ 
    activeField = textView.frame; 
} 

-(BOOL) textFieldShouldBeginEditing:(UITextField*)textField { 
    activeField = textField.frame; 
    return YES; 
} 

이 코드 시도에

-(void)viewWillAppear:(BOOL)animated 
{ 
[super viewWillAppear:YES]; 
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWasShown:) name: UIKeyboardDidShowNotification object:nil]; 

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillBeHidden:) name:UIKeyboardWillHideNotification object:nil]; 
} 

#pragma mark Keyboard Events 

-(BOOL)textFieldShouldReturn:(UITextField *)textField 
{ 
    [textField resignFirstResponder]; 
    return NO; 
} 

#pragma GCC diagnostic ignored "-Wdeprecated-declarations" 
-(void)keyboardWasShown:(NSNotification *)aNotification 
{ 

if (displayKeyboard==YES) { 
    return; 
} 
NSDictionary* info = [aNotification userInfo]; 
NSValue* aValue = [info objectForKey:UIKeyboardBoundsUserInfoKey]; 
//NSValue* aValue = [info objectForKey:UIKeyboardFrameBeginUserInfoKey]; 
CGSize keyboardSize = [aValue CGRectValue].size; 


offset = _scrollView.contentOffset; 

CGRect viewFrame = _scrollView.frame; 

viewFrame.size.height -= keyboardSize.height-tabbarHt; 
_scrollView.frame = viewFrame; 

CGRect textFieldRect = [activeField frame]; 
textFieldRect.origin.y += 10; 
[_scrollView scrollRectToVisible: textFieldRect animated:YES]; 
displayKeyboard = YES; 

} 

-(void)keyboardWillBeHidden:(NSNotification *)aNotification 
{ 

if (!displayKeyboard) { 
    return; 
} 

_scrollView.frame = CGRectMake(0, 0, 1024, 655); 
_scrollView.contentOffset =offset; 
displayKeyboard = NO; 
} 

-(BOOL) textFieldShouldBeginEditing:(UITextField*)textField { 
activeField = textField; 
return YES; 
} 
+0

UITextViewDelegate 메서드에서 스크롤 방법을 설정해야합니다. – Hiren

+0

@CocoaMatters 그 일을 수행하는 방법을 알려주시겠습니까? – southpark

+0

어떻게 UITextField를하고 있습니까? – Hiren

답변

0

가지 적어 위임 .. 코드입니다. textField rect 크기 만 지정할 때마다. 텍스트 뷰를 호출하면 텍스트 뷰 프레임 크기를 전달해야합니다.

+0

코드로 내 질문을 편집했다.하지만 activeField는 UItextField 객체이다 ... 나는 Uitextview와 비슷한 객체를 만들어야 하나? – southpark

+0

한 가지는 새로운 객체가 아닌 UItextField와 UItextView에서 직접 프레임을 전달합니다. – Hiren

+0

그래도 알아 냈습니다. 당신의 도움을 주셔서 감사합니다. – southpark