Another take on the “keyboard obscures UITextField” problem

后端 未结 3 1995
不思量自难忘°
不思量自难忘° 2021-01-13 13:56

I know that this is a common problem and the UITableViewController fixed this is iPhone SDK 3.0, but the UITableViewController is not working as I expect, probably due to ho

相关标签:
3条回答
  • 2021-01-13 14:34

    If you select the last item in table, it really cannot scroll above keyboard, because there's not enough table to scroll. It does scroll as far as it can, but that might not be enough to bring the selected item visible.

    What I did was resize the table to be fully visible just above the keyboard. It's not as smooth as it should be, but good enough == each and every item can be visible.

    0 讨论(0)
  • 2021-01-13 14:38

    (Repeating my answer from another SO question):

    I personally highly recommend using TPKeyboardAvoiding by Michael Tyson.

    It's very easy to use... (quoting from the Read Me):

    For use with UITableViewController classes, drop TPKeyboardAvoidingTableView.m and TPKeyboardAvoidingTableView.h into your project, and make your UITableView a TPKeyboardAvoidingTableView in the xib. If you're not using a xib with your controller, I know of no easy way to make its UITableView a custom class: The path of least resistance is to create a xib for it.

    For non-UITableViewControllers, drop the TPKeyboardAvoidingScrollView.m and TPKeyboardAvoidingScrollView.h source files into your project, pop a UIScrollView into your view controller's xib, set the scroll view's class to TPKeyboardAvoidingScrollView, and put all your controls within that scroll view. You can also create it programmatically, without using a xib - just use the TPKeyboardAvoidingScrollView as your top-level view.

    0 讨论(0)
  • 2021-01-13 14:49

    Resize it; if you want it smooth then use animation block.

    [UIView beginAnimations:@"tableAnim" context:nil];
    // 214 = keyboard size, adjust it if you have navigation bar or status bar
    tableView.frame = CGRectMake(0, 0, 320, 480 - 214);
    [UIView commitAnimations];
    
    0 讨论(0)
提交回复
热议问题