Is there a change to the behaviour of UIKeyboardWillShowNotification in iOS 8?

落爺英雄遲暮 提交于 2019-12-30 07:29:49

问题


I have had a simple UIView block animation that handles animating a group of text fields into view when the keyboard will show (and animate them back when the keyboard hides). This has worked fine in iOS 6 & 7, but now I'm getting incorrect behavior, and it all points to some change in UIKeyboardWillShowNotification.

I set up an isolated project to test this further on a single text field, with two buttons that call exactly the same methods that are fired for the keyboard's WillShow and WillHide notifications. See the results in this video:

Video example

This seems like a bug to me, or it might be a change to the behavior of this notification. Does anyone know if this is intended and/or what can be done about it?

Here is the relevant code:

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

来源:https://stackoverflow.com/questions/26279753/is-there-a-change-to-the-behaviour-of-uikeyboardwillshownotification-in-ios-8

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!