UIKeyboard将在iOS8及更高版本中显示和隐藏通知方法正常工作,但在iOS7中不起作用。还有其他选择吗?
我的应用程序部署目标是iOS7。
我的代码在这里
- (void)viewDidLoad
{
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardWasShown:)
name:UIKeyboardWillShowNotification
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(HideKeyboard:)
name:UIKeyboardWillHideNotification
object:nil];
}
- (void)keyboardWasShown:(NSNotification *)sender
{
CGSize kbSize =
[[[sender userInfo] objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue].size;
if (!scroll) {
scrollValue = self.WholeScreenUIView.frame.origin.y - kbSize.height;
}
scroll = YES;
}
- (void)HideKeyboard:(NSNotification *)sender
{
scroll = NO;
scrollValue = 0.0;
}
提前致谢。
答案 0 :(得分:0)
使用此代码..
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardWillHideHandler:)
name:UIKeyboardWillHideNotification
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardWillshowHandler:)
name:UIKeyboardWillShowNotification
object:nil];
- (void) keyboardWillHideHandler:(NSNotification *)notification {
[scroll setContentOffset:CGPointMake(0, 0) animated:YES];
}
- (void) keyboardWillshowHandler:(NSNotification *)notification {
[scroll setContentSize:CGSizeMake(self.view.frame.size.width, self.view.frame.size.height+44)];
}
希望这会有所帮助。这适用于我的情况