ANKeyboardObserverManager可以使键盘观察更加简单和灵活。
要安装 ANKeyboardObserverManager,您可以选择以下其中一种方法:
pod 'ANKeyboardObserverManager'
您可以直接使用 `[ANKeyboardObserverManager sharedManager]` 或者在需要使用它的类中分配并初始化 ANKeyboardObserverManager 实例。
然后添加观察者
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[[ANKeyboardObserverManager sharedManager] addKeyboardObserver:self
withkeyboardWillShowBlock:^(CGRect keyboardEndFrame, NSTimeInterval animateDuration, NSDictionary *info) {
your code
}
keyboardWillHideBlock:^(CGRect keyboardEndFrame, NSTimeInterval animateDuration, NSDictionary *info) {
your code
}];
}
当您不再需要观察键盘时,请删除观察者
- (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
[[ANKeyboardObserverManager sharedManager] removeKeyboardObserver:self];
}