我在 UIscrollView 中出现键盘问题。
我添加了一个 UIScrollview 作为
scrlView=[[UIScrollView alloc] initWithFrame:CGRectMake(10, 140, 1000, 600)];
scrlView.scrollEnabled=YES;
scrlView.showsVerticalScrollIndicator=YES;
scrlView.bounces=NO;
在此滚动视图中,我添加了 10 行 UITextField,每行有 5 个文本字段,每个文本字段高度为 50 像素。当试图编辑文本字段时,它与键盘重叠。为此,我尝试了这段代码
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardWasShown:)
name:UIKeyboardDidShowNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardWillBeHidden:)
name:UIKeyboardWillHideNotification object:nil];
- (void)keyboardWasShown:(NSNotification*)aNotification
{
NSDictionary* info = [aNotification userInfo];
CGSize kbSize = [[info objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size;
CGRect bkgndRect = selectetTxtfld.superview.frame;
bkgndRect.size.height += kbSize.height;
[selectetTxtfld.superview setFrame:bkgndRect];
[scrlView setContentOffset:CGPointMake(0.0, selectetTxtfld.frame.origin.y) animated:YES];
}
}
// 在发送 UIKeyboardWillHideNotification 时调用
- (void)keyboardWillBeHidden:(NSNotification*)aNotification
{
UIEdgeInsets contentInsets = UIEdgeInsetsZero;
[UIView animateWithDuration:0.4 animations:^{
scrlView.contentInset = contentInsets;
}];
scrlView.scrollIndicatorInsets = contentInsets;
}
但是 textField 没有出现在键盘上。它出现在滚动视图的 ypoint 位置
帮我解决这个问题。我在 StackOverFlow 中看到了很多答案。但没有解决我的问题