Добавить наблюдателей в viewWillAppear
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWasShown:) name:UIKeyboardDidShowNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillBeHidden:) name:UIKeyboardDidHideNotification object:nil];
Удалить наблюдателя в viewWillDisappear
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillHideNotification object:nil];
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillShowNotification object:nil];
Теперь добавьте эти методы в контроллере представления
#pragma mark - keyboard Hide Show
-(void) keyboardWasShown:(NSNotification *)notification
{
//Manages scrollview content on keyboard hide show
NSDictionary *info = [notification userInfo];
NSValue *kbFrame = [info objectForKey:UIKeyboardFrameEndUserInfoKey];
CGRect keyboardFrame = [kbFrame CGRectValue];
CGFloat height = keyboardFrame.size.height;
[_scrollView setContentInset:UIEdgeInsetsMake(0, 0, height, 0)];
[_scrollView setScrollIndicatorInsets:UIEdgeInsetsMake(0, 0, height, 0)];
}
- (void) keyboardWillBeHidden:(NSNotification *)notification
{
//Manages scrollview content on keyboard hide show
UIEdgeInsets contentInsets = UIEdgeInsetsZero;
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.3f];
[_scrollView setContentInset:UIEdgeInsetsMake(0, 0, 0, 0)];
[_scrollView setScrollIndicatorInsets:UIEdgeInsetsMake(0, 0, 0, 0)];
[UIView commitAnimations];
}
#pragma mark - Textfield Delegate Methods -
- (void)textFieldDidBeginEditing:(UITextField *)textField
{
CGRect r = [textField convertRect:textField.frame toView:_scrollView];
[self.scrollView scrollRectToVisible:r animated:YES];
}
Быстрое решение может быть помните 'contentOffset.y' в другой глобальной переменной и установите 'tblemailconfiguration' для сохранения contentOffset в делегате' textFieldShouldReturn'. –
Укажите код? –
Хорошо, я добавил ответ. –