我在UiscrollView中出现键盘问题。当键盘显示滚动视图时,textfield消失
我增加一个UIScrollView作为
scrlView=[[UIScrollView alloc] initWithFrame:CGRectMake(10, 140, 1000, 600)];
scrlView.scrollEnabled=YES;
scrlView.showsVerticalScrollIndicator=YES;
scrlView.bounces=NO;
该滚动视图我已经加入10行UITextFields的每一行有5个文本框的每个文本框的高度是50像素。 当曾经试图编辑文本字段它是由keyBoard.For重叠,我试图验证码
[[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;
}
但文本框不出现在keyboard.it出现在scrollview ypoint的位置
帮助我解决这个问题。我看到很多答案StackOverFlow.But未清除我的问题
在scrlView.contentInset显示错误= UIEdgeInsetMake(0,0,kbSize.height,0);指定'UIEdgeInsets'(又名'struct UIEdgeInsets')不兼容类型'int' – sudheer
在[scrlView setContentOffset:offSetAfterKeyboardIsDisplayed]中显示错误将'const CGFloat'(又名'const float')发送到不兼容类型'CGPoint' 'struct CGPoint') – sudheer
tnks for answers again.It现在对我非常重要 – sudheer