Ios UIKeyboardWillChangeFrameNotification在textViewDidBeginEditing之前调用,但在textFieldDidBeginEditing之后调用?为什么?
我的ViewController中有以下观察者Ios UIKeyboardWillChangeFrameNotification在textViewDidBeginEditing之前调用,但在textFieldDidBeginEditing之后调用?为什么?,ios,cocoa-touch,uitextfield,uitextview,Ios,Cocoa Touch,Uitextfield,Uitextview,我的ViewController中有以下观察者 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillChangeFrame:) name:UIKeyboardWillChangeFrameNotification object:nil]; 此视图控制器还符合UITextFieldDelegate和UITextViewDelegate,并实现textFieldDidBeginE
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillChangeFrame:) name:UIKeyboardWillChangeFrameNotification object:nil];
此视图控制器还符合UITextFieldDelegate和UITextViewDelegate,并实现textFieldDidBeginEditing
和textViewDidBeginEditing
现在,这是奇怪的部分
如果点击UITextField,调用顺序为textfieldDiBeginediting
,然后键盘将更改帧:
如果点击UITextView,调用顺序为键盘将更改框架,然后点击“textViewDidBeginEditing”
有人不觉得这有什么问题吗?无论文本是字段还是视图,都不应该首先调用text uu__; DidBeginEditing。为什么会这样
这导致了奇怪的动画问题。我需要它以这种或那种方式保持一致。我相信您可以使用UIKeyboardWillShowNotification,以及类似于上述代码的代码来完成您的任务:
- (void)keyboardWillShowNotification:(NSNotification*)notification {
NSDictionary *info = notification.userInfo;
CGRect r = [info[UIKeyboardFrameEndUserInfoKey] CGRectValue];
r = [self.view convertRect:r fromView:nil];
UIViewAnimationCurve curve = [info[UIKeyboardAnimationCurveUserInfoKey] integerValue];
double duration = [info[UIKeyboardAnimationDurationUserInfoKey] doubleValue];
[UIView beginAnimations:nil context:nil];
[UIView setAnimationCurve:curve];
[UIView setAnimationDuration:duration];
/* view changes */
[UIView commitAnimations];
}
使用UIKeyboardDidChangeFrameNotification而不是UIKeyboardWillChangeFrameNotification。我可以问你为什么要使用UIKeyboardWillChangeFrameNotification吗?我刚做了。@Everton制作了向上视图的动画,以适应键盘的不断增长。我的UITextView或多或少占据了90%的视图。当键盘出现在屏幕上时,我会将UITextView的高度设置为高于键盘。当键盘消失时,我会设置它的动画并将其还原。