4

I have a scrollview with multiple views on it. All these views have text field on them and once clicked the keyboard pops up. In certain cases the keyboard may hide this subview and I want to determine if this can be calculated in advance. If yes than how can I do it..? Can the scrollRectToVisible of UIScrollView method be used here to any use.. ? you look at the attached image for further clarification. Thanks for any ideas..

EDIT: These subviews are dynamically drawn so I can't determine and hard code this.

enter image description here

Ankit Srivastava
  • 12,347
  • 11
  • 63
  • 115
  • check this (keyboard size and "if active text field is hidden") in http://developer.apple.com/library/ios/#documentation/StringsTextFonts/Conceptual/TextAndWebiPhoneOS/KeyboardManagement/KeyboardManagement.html – TonyMkenu Mar 12 '13 at 08:42
  • 1
    @TonyMkenu thanks.. seems the way to go.. how about you post this as an answer and I can select it. – Ankit Srivastava Mar 12 '13 at 12:16
  • is somewhat.. similar to... what @Jordan said.. so you can accept his answer :) Tks P.S. You can also check http://www.iphonesampleapps.com/2009/12/adjust-uitextfield-hidden-behind-keyboard-with-uiscrollview/ and http://www.devedup.com/index.php/tag/inputs-hidden/ – TonyMkenu Mar 12 '13 at 12:42

3 Answers3

4

In Landscape mode :

Height of iPad : 768 pixels.

Height of Keyboard : 352 pixels.

Which means keyboard x co-ordinates : 0.0 and y co-ordinates : 416

Whenever your controls y co-ordinates are greater then 416. Understand it'll be hidden when keyboard will pop-up.

Rushi
  • 4,553
  • 4
  • 33
  • 46
1

Yeah , you need to shift the subview a little up so that it can be visible, you can use this animation to shift it to any point. Just pass the layer and destination point. and once user pressed return on keyboard, shift it again to the previous point :)

-(void)moveLayer:(CALayer*)layer to:(CGPoint)point
{
    // Prepare the animation from the current position to the new position
    CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"position"];
    animation.fromValue = [layer valueForKey:@"position"];
    animation.duration = 0.2;

    animation.toValue = [NSValue valueWithCGPoint:point];

    // Update the layer's position so that the layer doesn't snap back when the animation completes.
    layer.position = point;

    // Add the animation, overriding the implicit animation.
    [layer addAnimation:animation forKey:@"position"];
}
Bhupendra
  • 2,525
  • 18
  • 20
1

Register for the following notification:

[[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(keyboardDidChangeFrame:)
                                                 name:UIKeyboardDidChangeFrameNotification
                                               object:nil];

Make sure you handle this:

- (void)keyboardDidChangeFrame:(NSNotification *)notification
{
    CGRect keyboardEndFrame;
    [[notification.userInfo objectForKey:UIKeyboardFrameEndUserInfoKey] getValue:&keyboardEndFrame];
    CGRect keyboardFrame = [self.view convertRect:keyboardEndFrame fromView:nil];

    // Add your code to check if the keyboard is hiding your views.
    // CGRectIntersectsRect should help you here.
    // For each view you are worried about hiding, run CGRectIntersectsRect to check
    // if an intersection occurs. If it does, then you can
    // move your view using UIScrollView's setContentOffset: animated: method.

}
Jordan Smith
  • 10,310
  • 7
  • 68
  • 114