Move UITextField in custom UITableViewCell to the center of the screen so the keyboard won't cover it [duplicate]

左心房为你撑大大i 提交于 2019-12-11 09:03:16

问题


I have a form that the user of the app must fill in order to register to the service. However, as there are many fields that need to be filled, some of them are at the bottom of the screen, so when the keyboard appears, the field is covered and the user can't see what's typed.

I'm using a UITableView with custom Prototype Cells, each one has a UITextField named textField.


回答1:


There are a lot of solutions to your problem. You can use this. There's a sample code which handles the keyboard animation for UITableView as well.




回答2:


you move table up when user start typing.

- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
[UIView beginAnimations:nil context:self.tableView];
            [UIView setAnimationDuration:0.25];
             [self.view setFrame:CGRectMake(0, -130, 320, 460)];
            [UIView commitAnimations];
return YES;
}



回答3:


Hi try this code hope will help

-(void)textFieldDidBeginEditing:(UITextField *)textField
{

  UITableViewCell *newcell = (UITableViewCell*) [[textField superview] superview];

    [tbl_view scrollToRowAtIndexPath:[tbl_view indexPathForCell:newcell] atScrollPosition:UITableViewScrollPositionTop animated:YES];

}


来源:https://stackoverflow.com/questions/15757201/move-uitextfield-in-custom-uitableviewcell-to-the-center-of-the-screen-so-the-ke

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!