我正在运行ios8b4,并且我有一些注册键盘通知的代码可以为我的视图设置动画。
Class KeyboardAdjuster
- (void)registerForKeyboardNotifications {
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
}
- (void)unregisterForKeyboardNotifications {
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillShowNotification object:nil];
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillHideNotification object:nil];
}
在视图控制器的外观方法中调用它们。 self.keyboardAdjuster不是nil(已验证),我可以进入注册方法,这两个通知应该注册。在视图控制器消失之前,没有调用取消注册。
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[self.keyboardAdjuster registerForKeyboardNotifications];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(searchEvent:) name:[SCWebSearchEvent identifier] object:nil];
}
- (void)viewWillDisappear:(BOOL)animated {
[[NSNotificationCenter defaultCenter] removeObserver:self name:[SCWebSearchEvent identifier] object:nil];
self.navigationController.navigationBar.translucent = NO;
[self.keyboardAdjuster unregisterForKeyboardNotifications];
[super viewWillDisappear:animated];
}
此外,每当调用textview或textfield时,我的选择器都会在iOS模拟器中被完美调用,但出于某种原因,在我的设备上运行时,它们永远不会被调用。在设备和模拟器上运行时还有什么我需要做的吗?