Keyboard blocking UITableViewCell's UITextField?

雨燕双飞 提交于 2019-12-04 18:48:29
MGA

If i'm understanding your question correctly, you want the view to scroll when the keyboard shows up. If you make your viewController a subclass of UITableViewController, I believe you get scrolling for free. The only other option is unfortunately not that simple. You need to play around with the delegation methods to move your view up and down (and animate it if you want it to slide up with the keyboard). There's lots of answers to this you can find so I won't go into the details, here's a few links to help you out!

In depth explation here

Great explanation here

Some UIScrollView details here

More here

That worked pretty well for me, in case somebody still need the answer:

- (void)textFieldDidBeginEditing:(UITextField *)textField
{
    if (self.tableView.contentOffset.y == 0)
    {
        [UIView animateWithDuration:0.0 delay:0.5 options:UIViewAnimationOptionAllowUserInteraction animations:^{
        } completion:^(BOOL finished) {
            UITableViewCell *cell = (UITableViewCell*) [[textField superview] superview];
            [self.tableView scrollToRowAtIndexPath:[self.tableView indexPathForCell:cell] atScrollPosition:UITableViewScrollPositionTop animated:YES];
        }];
    }
}

The problem was that the keyboard was not taken into consideration when sliding to the cell, so I just added the call in a small delay block.

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