Я почесал голову, чтобы исправить это. У меня есть UITableView
с UITextView
и UIPickerView
следующим образом:
1. В каждой строке есть UITextView
2. В последней строке есть UITextView
и нередактируемый UITextField
, который открывает UIPickerView
Вот скриншот:
Элемент управления с текстом Все — это UITextField
, который открывает UIPickerView
.
Ниже приведены проблемы, с которыми я столкнулся при их анимации:
1. При отставке UITextView
UITableView
прокручивается вверх (должно прокручиваться до позиции UITextView
). Пробовал с scrollToRowAtIndexPath
, все равно не помогает.
- (BOOL)textViewShouldEndEditing:(UITextView *)textView
{
txtViewActive = nil;
[self animateTextView:NO];
return YES;
}
- (void)textViewDidBeginEditing:(UITextView *)textView
{
[txtUser resignFirstResponder];
[pickerView removeFromSuperview];
if ([textView.text isEqualToString:NSLocalizedString(@"write_a_reply", nil)]) {
textView.text = @"";
textView.textColor = [UIColor blackColor];
}
[self animateTextView:YES];
}
- (void) animateTextView: (BOOL) up
{
const int movementDistance = 140;
const float movementDuration = 0.3f;
int movement = (up ? -movementDistance : movementDistance);
[UIView beginAnimations: @"anim" context: nil];
[UIView setAnimationBeginsFromCurrentState: YES];
[UIView setAnimationDuration: movementDuration];
self.view.superview.frame = CGRectOffset(self.view.superview.frame, 0, movement);
[tableMessageDetail scrollToRowAtIndexPath:indexPathScrollTo
atScrollPosition:UITableViewScrollPositionNone
animated:YES];
[UIView commitAnimations];
}
Как я создаю
UIPickerView
, я не могу анимировать, когда появляется клавиатура.txtUser = [[UITextField alloc]init]; UIToolbar *toolbarUsers = [[UIToolbar alloc] init]; [toolbarUsers setBarStyle:UIBarStyleDefault]; [toolbarUsers sizeToFit]; UIBarButtonItem *flexButtonUsers = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self action:nil]; UIBarButtonItem *doneButtonUsers =[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(resignKeyboard)]; NSArray *itemsArrayUsers = [NSArray arrayWithObjects:flexButtonUsers, doneButtonUsers, nil]; [toolbarUsers setItems:itemsArrayUsers]; [txtUser setInputAccessoryView:toolbarUsers]; arrUsers = [NSMutableArray new]; [arrUsers addObject:NSLocalizedString(@"all", nil)]; [arrUsers addObject:[[message.MessageByFirstName componentsSeparatedByString:@" "] objectAtIndex:0]]; pickerView = [[UIPickerView alloc] initWithFrame:CGRectMake(0, self.view.frame.size.height - 150, self.view.frame.size.width, 150)]; [pickerView setDataSource: self]; [pickerView setDelegate: self]; pickerView.showsSelectionIndicator = YES; txtUser.inputView = pickerView;
Я ищу стабильное решение, где:
- Анимации клавиатуры
UITextView
иUIPickerView
не будут конфликтовать (двойная анимация, если пользователь сначала нажимаетUITextView
, а затемUITextField
)UIPickerView
анимация
Вероятно, UIKeyboardWillShowNotification
и UIKeyboardWillHideNotification
удобны, но я не могу использовать их чисто.