Question

I'm presenting a view in a modal form sheet. It works, but the keyboard blocks the lower half of the screen in landscape (and a small portion of the screen in portrait). How do I compensate for the keyboard on the iPad?

The UI is basically a large text box on the left 3/4ths of the screen, and a strip of photos along the right edge in a tableview. I need the tableview to resize so the user can scroll to see the last one.

(I've read how to do this on the iPhone, but the same code does not work on the iPad.)

Note UI

(There are 3.5 photos below under the keyboard, but the table view will bounce back to this position if you try to scroll it down.)

Was it helpful?

Solution

My problem was caused by assigning the first responder in viewWillAppear. At that point, the keyboard notification fires but the coordinates in it once converted to the new view aren't valid, because the view hasn't actually appeared.

So instead of doing this:

- (void)viewWillAppear: (BOOL)animated {
    [super viewWillAppear: animated];

    // register for keyboard events here

    [_field becomeFirstResponder];
}

I'm now doing this:

- (void)viewWillAppear: (BOOL)animated {
    [super viewWillAppear: animated];

    // register for keyboard events here

    dispatch_async(dispatch_get_main_queue(), ^{
        [_field becomeFirstResponder];
    });
}

Otherwise, the problem is pretty straightforward: find the keyboard frame, convert it to local coordinates, adjust views to duck it.

I posted a test project to github: Keyboard Ducker

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top