저는 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;
}
UITextViewDelegate 메서드에서 스크롤 방법을 설정해야합니다. – Hiren
@CocoaMatters 그 일을 수행하는 방법을 알려주시겠습니까? – southpark
어떻게 UITextField를하고 있습니까? – Hiren