将自定义UITableViewCell中的UITextField移动到屏幕的中心,以便键盘不会覆盖它
我有一个表格,应用程序的用户必须填写,以注册服务。 但是,由于需要填充的字段很多,其中一些字段位于屏幕的底部,所以当键盘出现时,字段被覆盖,用户看不到键入的内容。
我正在使用UITableView
自定义Prototype Cells
,每个人都有一个名为textField
的UITextField
。
你的问题有很多解决scheme。 你可以使用这个 。 还有一个示例代码,它也处理UITableView
的键盘animation。
当用户开始input时,将表格向上移动。
- (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; }
嗨试试这个代码希望会有所帮助
-(void)textFieldDidBeginEditing:(UITextField *)textField { UITableViewCell *newcell = (UITableViewCell*) [[textField superview] superview]; [tbl_view scrollToRowAtIndexPath:[tbl_view indexPathForCell:newcell] atScrollPosition:UITableViewScrollPositionTop animated:YES]; }