3

How to scroll UITextField, UITextview in UITableView or in UIViewController when keyboard appears on the screen.

Arun
  • 85
  • 1
  • 1
  • 8
  • http://stackoverflow.com/questions/1126726/how-to-make-a-uitextfield-move-up-when-keyboard-is-present – Sport Jan 31 '14 at 09:22
  • https://developer.apple.com/library/ios/documentation/StringsTextFonts/Conceptual/TextAndWebiPhoneOS/KeyboardManagement/KeyboardManagement.html look this also – Sport Jan 31 '14 at 09:23

2 Answers2

3

I'm using IQKeyboardManager. In general it's as easy as adding [IQKeyBoardManager installKeyboardManager]; to a viewDidLoad method.

kovpas
  • 9,617
  • 6
  • 36
  • 42
1

Just handle the textView/textField delegate methods and adjust your view frame accordingly.

You can also add all the controls inside a scroll view and then scroll up/down within the following delegate methods

-(void)textFieldDidBeginEditing:(UITextField *)textField
{
    scrollView.frame = CGRectMake(scrollView.frame.origin.x,
                                  scrollView.frame.origin.y,
                                  scrollView.frame.size.width,
                                  scrollView.frame.size.height - 215 + dynamicHeight);
}

-(void)textFieldDidEndEditing:(UITextField *)textField
{
    scrollView.frame = CGRectMake(scrollView.frame.origin.x,
                                  scrollView.frame.origin.y,
                                  scrollView.frame.size.width,
                                  scrollView.frame.size.height + 215 - dynamicHeight);
}

You can also set notification to fire the -keyboardWillShow and -keyboardWillHide methods.

There are these 3rd party library availabe on github.
Just google it and you will find loads of them.

https://github.com/michaeltyson/TPKeyboardAvoiding

staticVoidMan
  • 15,908
  • 4
  • 55
  • 91
gaurish.salunke
  • 919
  • 8
  • 14