我在UITableView
有UITextField
,当我单击UITextField
我已经移动了偏移量,但是我的问题是,当用户滚动到下一个字段时,它会显示奇怪的行为,有时输入刷新或焦点将返回到先前的UITextField
。
See this code and impelement According ur project
(BOOL)textFieldShouldBeginEditing:(UITextField *)textField{
[self scrollViewToCenterOfScreen:textField];
return YES; }
(void)scrollViewToCenterOfScreen:(UIView *)theView {
CGFloat viewCenterY = theView.center.y;
CGRect applicationFrame = [[UIScreen mainScreen] applicationFrame];
CGFloat availableHeight = applicationFrame.size.height - 200; // Remove area covered by keyboard
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 are tectField name.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.