嗨,我正在使用以下方法来提升键盘,我有许多视图控制器也可以使用它,但我尝试委派它失败了。我绝对不想将它插入到每个视图控制器中。如果有任何想法将不胜感激
- (void)viewWillAppear:(BOOL)animated {
void (^keyBoardWillShow) (NSNotification *)= ^(NSNotification * notif) {
NSDictionary* info = [notif userInfo];
NSValue* aValue = [info objectForKey:UIKeyboardFrameEndUserInfoKey];
CGSize keyboardSize = [aValue CGRectValue].size;
float bottomPoint = (ivcTextField.frame.origin.y + ivcTextField.frame.size.height + 10);
scrollAmount = keyboardSize.height - (self.view.frame.size.height - bottomPoint);
if (scrollAmount > 0) {
moveViewUp =YES;
[self scrollTheView:YES];
}
else
moveViewUp = NO;
};
[[NSNotificationCenter defaultCenter] addObserverForName:UIKeyboardWillShowNotification object:self.view.window queue:nil
usingBlock:keyBoardWillShow];
void (^keyBoardWillHide) (NSNotification *)= ^(NSNotification * notif) {
if (moveViewUp) [self scrollTheView:NO];
};
[[NSNotificationCenter defaultCenter] addObserverForName:UIKeyboardWillHideNotification object:self.view.window queue:nil
usingBlock:keyBoardWillHide];
[super viewWillAppear:animated];
} - (void)viewWillDisappear:(BOOL)animated {
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillShowNotification object:nil];
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillHideNotification object:nil];
[super viewWillDisappear:animated];
}