2014-11-19 5 views
0

키보드 위의 단추가있는 툴바를 놓아 버립니다. textview를 위아래로 움직이는 동안 문제가 있습니다. textview 키보드 스크롤 rect에 의해 덮여 있다면 잘 작동합니다. 때로는 텍스트보기가 키보드로 덮여 있지 않지만 도구 모음이이를 다루고 있습니다. 이 경우에도 텍스트 뷰를 위로 올려 놓고 싶습니다. 텍스트 뷰를 탭하면 툴바 위로 이동해야합니다. 현재 내 textview는 도구 모음으로 덮여있을 때 위로 움직이지 않습니다. 이것을 달성하는 방법?텍스트 필드를 탭하여 텍스트 필드를 위아래로 이동하는 중에 문제가 발생합니다.

// Called when the UIKeyboardDidShowNotification is sent. 
- (void)keyboardWasShown:(NSNotification*)aNotification 
{ 
    NSDictionary* info = [aNotification userInfo]; 
    CGSize kbSize = [[info objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size; 
    UIEdgeInsets contentInsets = UIEdgeInsetsMake(0.0, 0.0, kbSize.height, 0.0); 
    scroll.contentInset = contentInsets; 
    scroll.scrollIndicatorInsets = contentInsets; 

    // If active text field is hidden by keyboard, scroll it so it's visible 
    // Your app might not need or want this behavior. 
    CGRect aRect = self.view.frame; 
    aRect.size.height -= kbSize.height; 
    if (!CGRectContainsPoint(aRect, activeField.frame.origin)) { 
     [self.scroll scrollRectToVisible:activeField.frame animated:YES]; 
    } 
} 

// Called when the UIKeyboardWillHideNotification is sent 
- (void)keyboardWillBeHidden:(NSNotification*)aNotification 
{ 
    UIEdgeInsets contentInsets = UIEdgeInsetsZero; 
    scroll.contentInset = contentInsets; 
    scroll.scrollIndicatorInsets = contentInsets; 
} 
// Call this method somewhere in your view controller setup code. 
- (void)registerForKeyboardNotifications 
{ 
    [[NSNotificationCenter defaultCenter] addObserver:self 
              selector:@selector(keyboardWasShown:) 
               name:UIKeyboardDidShowNotification object:nil]; 

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

} 

//To add toolbar above textview 
UIToolbar* numberToolbar = [[UIToolbar alloc]initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, 30)]; 
      numberToolbar.barStyle = UIBarStyleBlackTranslucent; 
      numberToolbar.items = [NSArray arrayWithObjects: 
            [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil], 
            [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil], 
            [[UIBarButtonItem alloc]initWithTitle:AGLocalizedString(@"key_done",nil) style:UIBarButtonItemStyleDone target:self action:@selector(returnKeyboardOnDone)], 
            nil]; 
      [numberToolbar sizeToFit]; 
      subTitleTxtFld.inputAccessoryView = numberToolbar; 
      compaintSummaryTxt.inputAccessoryView = numberToolbar; 
      aeTxtView.inputAccessoryView = numberToolbar; 

답변

0

키보드 크기 높이 대신 유지 (키보드 크기 높이 + 도구 모음 높이) 대신 도구 모음의 참조 변수를 사용하십시오. 그것은 그 일을 할 것입니다.

UIEdgeInsets contentInsets = UIEdgeInsetsMake(0.0, 0.0, kbSize.height + toolBar.frame.size.height, 0.0); 
+0

따라 당신은 키보드와 툴바가없는 일부에만 키보드 위의 툴바를 여러 UITextFields 및 UITextViews, 그들 중 일부가있는 경우 경우를 처리해야합니다. –

0

rect를 만들고 스크롤하는 대신 caretRect를 스크롤하십시오.

CGRect caretRect = [self.textView caretRectForPosition:self.textView.selectedTextRange.end]; 
// add some extra space to scroll 
caretRect.size.height += 7; 
[self.textView scrollRectToVisible:caretRect animated:YES];