Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iPhone - Keyboard hides TextField

Tags:

I am using UITextField to receive user inputs. However, since my textfields are towards the middle/bottom of the nib, it gets hidden when the keyboard pops up. Is there any way sort of slide it along with the keyboard so that it's on the top of the keyboard during selection? Also, since I am also using the numberpad, is there an easy way to include a done button somewhere?

Thanks for the help.

like image 437
intl Avatar asked Feb 21 '10 19:02

intl


People also ask

How do I hide the TextField keyboard?

When you click on the TextField it opens up the on-screen keyboard. To hide/dismiss the keyboard you have to press the back button in Android and the done button (inside the onscreen keyboard) in iOS.

Why is my iPad keyboard blocking my screen?

If your keyboard is still stuck, even after you docked it, try restarting your iPad. We like using Settings > General > Shut Down and then power back up to restart all types of iPads, with or without home buttons.

What is TextField in iOS?

A control that displays an editable text interface. iOS 13.0+ iPadOS 13.0+ macOS 10.15+ Mac Catalyst 13.0+ tvOS 13.0+ watchOS 6.0+


1 Answers

I have made a simple Application for this problem. It automatically checked the Textfield's position and if keyboard hides it , it will automatically move up as per need.

  - (void)textFieldDidBeginEditing:(UITextField *)textField {     [self animateTextField:textField up:YES]; }   - (void)textFieldDidEndEditing:(UITextField *)textField {     [self animateTextField:textField up:NO]; }   - (void) animateTextField: (UITextField*) textField up: (BOOL) up {     int animatedDistance;     int moveUpValue = textField.frame.origin.y+ textField.frame.size.height;     UIInterfaceOrientation orientation =     [[UIApplication sharedApplication] statusBarOrientation];     if (orientation == UIInterfaceOrientationPortrait ||         orientation == UIInterfaceOrientationPortraitUpsideDown)     {          animatedDistance = 216-(460-moveUpValue-5);     }     else     {         animatedDistance = 162-(320-moveUpValue-5);     }      if(animatedDistance>0)     {         const int movementDistance = animatedDistance;         const float movementDuration = 0.3f;          int movement = (up ? -movementDistance : movementDistance);         [UIView beginAnimations: nil context: nil];         [UIView setAnimationBeginsFromCurrentState: YES];         [UIView setAnimationDuration: movementDuration];         self.view.frame = CGRectOffset(self.view.frame, 0, movement);                [UIView commitAnimations];     } }  -(BOOL)textFieldShouldReturn:(UITextField *)textField {      [textField resignFirstResponder];     return YES; }  
like image 120
ValayPatel Avatar answered Oct 12 '22 03:10

ValayPatel