我在UITextField
中有UITableView
,当我点击UITextField
时,我移动了偏移量,但我的问题是用户滚动到下一个字段然后显示
一段时间输入刷新或焦点将返回到先前的UITextField
。奇怪的行为。
答案 0 :(得分:0)
根据您的项目
查看此代码和异常(BOOL)textFieldShouldBeginEditing:(UITextField *)textField {
[self scrollViewToCenterOfScreen:textField];
返回YES;
}
(void)scrollViewToCenterOfScreen:(UIView *)theView {
CGFloat viewCenterY = theView.center.y;
CGRect applicationFrame = [[UIScreen mainScreen] applicationFrame];
CGFloat availableHeight = applicationFrame.size.height - 200; //删除键盘覆盖的区域
CGFloat y = viewCenterY - availableHeight / 2.0;
if(y <0){
y = 0;
}
[scrollview setContentOffset:CGPointMake(0,y)animated:YES];
}
- (BOOL)textFieldShouldReturn:(UITextField *)textField {
if ([textField isEqual:txtStAppField])
{
[txtStConfirmField becomeFirstResponder];
}
else if ([textField isEqual:txtStConfirmField])
{
[txtDummyAppField becomeFirstResponder];
}
else if ([textField isEqual:txtStConfirmField])
{
[txtDummyConfirmFeild becomeFirstResponder];
}
else
{
[textField resignFirstResponder];
[scrollview setContentOffset:CGPointMake(0, 0) animated:YES];
}
return YES;
}
// txtStConfirmField,txtDummyConfirmFeild,txtDummyAppField,txtStConfirmField,txtStConfirmField是tectField名称。