Да, это возможно.Вам необходимо зарегистрироваться для получения следующих уведомлений:
UIKeyboardWillShowNotification и UIKeyboardWillHideNotification.
И назначить обработчики для каждого.
Затем в обработчиках необходимо настроить / уменьшить рамкуUITextView.Обратите внимание, что уведомление будет содержать объект с размерами клавиатуры.Вы должны использовать их, чтобы уменьшить текстовое представление на соответствующую сумму.
Here is some similar sample code you can refactor
// 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(keyboardWasHidden:)
name:UIKeyboardDidHideNotification object:nil];
keyboardShown=NO;
}
- (void)resizeTextView
{
float margin=[contentTextBox frame].origin.x;
//margin=0.0;
CGRect rect0 = [[container scrollView] frame];
CGRect rect1 = [contentTextBox frame];
//shrink textview if its too big to fit with textview
if(rect0.size.height<rect1.size.height){
rect1.size.height=rect0.size.height-2*margin;
[contentTextBox setFrame:rect1];
}
//make the textview visible if content is bigger than scroll view
if([[container scrollView] contentSize].height>[[container scrollView] frame].size.height){
CGPoint point = CGPointMake([[container scrollView] contentOffset].x,[contentTextBox frame].origin.y-margin);
[[container scrollView] setContentOffset:point animated:YES];
}
}
- (void)keyboardWasShown:(NSNotification*)aNotification
{
//keyboard is already visible just exit
if (keyboardShown)
return;
keyboardShown=YES;
//resize the content text box and scroll into view
if(activeTextView!=nil){
[self resizeTextView];
}
//scroll text field into view
if(activeTextField!=nil){
//get the text field rectangle
CGRect rect = [activeTextField frame];
//adjust to the current page of the scroll view
rect.origin.x=[[container scrollView] contentOffset].x;
[[container scrollView] scrollRectToVisible:rect animated:YES];
}
}
- (void)keyboardWasHidden:(NSNotification*)aNotification
{
//keyboard not visible just exit
if (!keyboardShown)
return;
keyboardShown=NO;
//resize the content text box
if(contentTextBox!=nil){
//find where the bottom of the texview should be from the label location
CGRect rect0=[contentTextBoxBottom frame];
//get the current frame
CGRect rect1=[contentTextBox frame];
//adjust width
rect1.size.width=rect0.size.width;
//adjust height
rect1.size.height=rect0.origin.y-rect1.origin.y;
//restore the size of the textview
[contentTextBox setFrame:rect1];
}
}