У меня есть приложение на основе контроллера табуляции, где у меня есть uitextview при выборе, который я перемещаю вверх, когда появляется клавиатура, все работает хорошо, пока я не переключу вкладку, когда я вернусь на эту вкладку и попробую редактировать в представлении uitextview перемещается вниз, а затем возвращается в нормальное положение на клавиатуре, вместо того, чтобы двигаться вверх. здесь полный кодЗачем просматривать вниз при показе клавиатуры?
- (void)textViewDidBeginEditing:(UITextView *)textField
{
[self keyboardWillShow];
}
-(void)textViewDidEndEditing:(UITextView *)textField
{
[self keyboardWillHide];
}
-(void)keyboardWillShow {
// Animate the current view out of the way
if (self.view.frame.origin.y >= 0)
{
[self setViewMovedUp:YES];
}
else if (self.view.frame.origin.y < 0)
{
[self setViewMovedUp:NO];
}
}
-(void)keyboardWillHide {
if (self.view.frame.origin.y >= 0)
{
[self setViewMovedUp:YES];
}
else if (self.view.frame.origin.y < 0)
{
[self setViewMovedUp:NO];
}
}
//method to move the view up/down whenever the keyboard is shown/dismissed
-(void)setViewMovedUp:(BOOL)movedUp
{
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.5]; // if you want to slide up the view
CGRect rect = self.view.frame;
if (movedUp)
{
// 1. move the view's origin up so that the text field that will be hidden come above the keyboard
// 2. increase the size of the view so that the area behind the keyboard is covered up.
rect.origin.y -= kOFFSET_FOR_KEYBOARD;
rect.size.height += kOFFSET_FOR_KEYBOARD;
}
else
{
// revert back to the normal state.
rect.origin.y += kOFFSET_FOR_KEYBOARD;
rect.size.height -= kOFFSET_FOR_KEYBOARD;
}
self.view.frame = rect;
[UIView commitAnimations];
}