1

In forms that are longer than 50% of the screen area, inputs will appear underneath the keyboard. I want to adjust the view to keep the selected input always visible when the keyboard shows and reset its position when the keyboard disappears.

Any ideas? Thanks.

swiftBoy
  • 35,607
  • 26
  • 136
  • 135

4 Answers4

3

The section Managing the Keyboard in the iPhone Application Programming Guide discusses how to receive notifications of keyboard display/undisplay, as well as how to keep your content visible (including sample code).

Sixten Otto
  • 14,816
  • 3
  • 48
  • 60
2

If you're in a UIScrollView, you can use the -scrollRectToVisible:animated: method to move to a particular portion of the view.

If you're in a UITableView, you can use the -scrollToRowAtIndexPath:atScrollPosition:animated: method to scroll to a particular row, or - scrollToNearestSelectedRowAtScrollPosition:animated:.

Jeff Kelley
  • 19,021
  • 6
  • 70
  • 80
0

Use https://github.com/michaeltyson/TPKeyboardAvoiding to manage Keyboards automatically

Saqib Saud
  • 2,799
  • 2
  • 27
  • 41
0

Try This Code:

#define kTextFieldMovementDistance      150.0 //You can set this according to your need
#define kMinimumMovementDuration        0.3f

- (void) slidingViewUpward: (BOOL) isSlidingUp
{
    CGFloat movementDistance = kTextFieldMovementDistance; 

    const float movementDuration = kMinimumMovementDuration;

    int movement = (isSlidingUp ? -movementDistance : movementDistance);

    [UIView beginAnimations: @"animation" context: nil];
    [UIView setAnimationBeginsFromCurrentState: YES];
    [UIView setAnimationDuration: movementDuration];
    self.view.frame = CGRectOffset(self.view.frame, 0, movement);

    [UIView commitAnimations];
}

When you want to slide the view in upwards Direction, or when the Keyboard became the first responder, the pass the bool value as YES otherwise NO.

Sahil Mahajan
  • 3,922
  • 2
  • 29
  • 43