我有一个简单的UIView
块动画,可以在键盘显示时处理一组文本字段的动画(并在键盘隐藏时将其设置为动画)。这在iOS 6& 7,但现在我的行为不正确,这一切都指向UIKeyboardWillShowNotification
的一些变化。
我设置了一个独立的项目,在单个文本字段上进一步测试,有两个按钮调用与键盘的WillShow
和WillHide
通知相同的方法。请参阅此视频中的结果:
这对我来说似乎是一个错误,或者可能是对此通知行为的更改。有谁知道这是否有意和/或可以做些什么呢?
以下是相关代码:
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
}
- (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillShowNotification object:nil];
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillHideNotification object:nil];
}
- (void)keyboardWillShow:(NSNotification *)notification
{
[UIView animateWithDuration:0.3 animations:^{
self.textField.frame = CGRectOffset(self.textField.frame, 0.f, _destY - _origY);
}];
}
- (void)keyboardWillHide:(NSNotification *)notification
{
[UIView animateWithDuration:0.3 animations:^{
self.textField.frame = CGRectOffset(self.textField.frame, 0.f, _origY - _destY);
}];
}