2014-11-19 1 views
0

Я поместил панель инструментов с кнопкой над клавиатурой, чтобы отменить ее. У меня проблема при перемещении текста вверх и вниз. Если текстовое покрытие закрыто с помощью прокрутки клавиатуры, то работает нормально. Иногда текст не покрывается клавиатурой, но панель инструментов закрывает его. Я хочу, чтобы textview также двигался вверх и в этом случае, и он должен перемещаться над моей панелью инструментов при нажатии на 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

Используйте ссылочную переменную вашей панели инструментов, в месте роста размера клавиатуры, Keep (клавиатура высота размер + высота панели инструментов). Это сделает работу.

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

И соответственно вы должны рассматривать дела, если есть несколько UITextFields и UITextViews, некоторые из них с панелью над клавиатурой, а некоторые только клавиатурой без ToolBar. –

0

Вместо того, чтобы делать прямые и прокручивать его, прокрутите каретку.

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];