iOS 8中UIKeyboardWillShowNotification的行为是否有变化?

时间:2014-10-09 13:31:33

标签: ios8 uiviewanimation nsnotificationcenter uikeyboard

我有一个简单的UIView块动画,可以在键盘显示时处理一组文本字段的动画(并在键盘隐藏时将其设置为动画)。这在iOS 6& 7,但现在我的行​​为不正确,这一切都指向UIKeyboardWillShowNotification的一些变化。

我设置了一个独立的项目,在单个文本字段上进一步测试,有两个按钮调用与键盘的WillShowWillHide通知相同的方法。请参阅此视频中的结果:

Video example

这对我来说似乎是一个错误,或者可能是对此通知行为的更改。有谁知道这是否有意和/或可以做些什么呢?

以下是相关代码:

- (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);
     }];
}

0 个答案:

没有答案