Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You can add these lines of coding:</p> <pre><code>//method to move the view up/down whenever the keyboard is shown/dismissed -(void)setViewMovedUp:(BOOL)movedUp { [UIView beginAnimations:nil context:NULL]; [UIView setAnimationDuration:0.3]; // if you want to slide up the view CGRect rect = self.view.frame; if (movedUp) { NSLog(@"MOVE-UP"); // 1. move the view's origin up so that the text field that will be hidden come above the keyboard // 2. increase the size of the view so that the area behind the keyboard is covered up. rect.origin.y -= kOFFSET_FOR_KEYBOARD; // rect.size.height += kOFFSET_FOR_KEYBOARD; } else { NSLog(@"MOVE-DOWN"); // revert back to the normal state. rect.origin.y += kOFFSET_FOR_KEYBOARD; // rect.size.height -= kOFFSET_FOR_KEYBOARD; } self.view.frame = rect; [UIView commitAnimations]; } -(void)keyboardWillShow { // Animate the current view out of the way if (self.view.frame.origin.y &gt;= 0) { [self setViewMovedUp:YES]; } else if (self.view.frame.origin.y &lt; 0) { [self setViewMovedUp:NO]; } } -(void)keyboardWillHide { if (self.view.frame.origin.y &gt;= 0) { [self setViewMovedUp:YES]; } else if (self.view.frame.origin.y &lt; 0) { [self setViewMovedUp:NO]; } } </code></pre> <p>And in viewDidAppear:</p> <pre><code> -(void)viewDidAppear:(BOOL)animated { [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow) name:UIKeyboardWillShowNotification object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide) name:UIKeyboardWillHideNotification object:nil]; } </code></pre> <p>you have to define this also #define kOFFSET_FOR_KEYBOARD 100.0//as you want</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload