Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>It can be done by adjusting the constraint to the bottom of the view when the keyboard appears and disappears. In the example below, I have a view controller with a tool bar and a text view. The text view has constraints (with a value of 20) to the bottom and sides of the main view, and one to the tool bar at the top of the view. I have an IBOutlet to the constraint to the bottom of the view. Notice that in the keyboardWillShow: method, I have to check on the orientation of the view in order to get the constraint's constant value correct -- in landscape mode, the keyboard's width and height are reversed (that is, what you get as size.width is actually the height, and size.height gives you the width).</p> <pre><code>@interface ViewController () @property (weak, nonatomic) IBOutlet NSLayoutConstraint *bottomCon; // outlet to the constraint between the text view and the bottom of the view @property (weak,nonatomic) IBOutlet UITextView *tv; // outlet for the text view @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardDidShow:) name:UIKeyboardDidShowNotification object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil]; } - (void)keyboardWillShow:(NSNotification*)aNotification { NSDictionary* info = [aNotification userInfo]; CGSize kbSize = [[info objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size; if (self.view.bounds.size.width &lt; self.view.bounds.size.height) { self.bottomCon.constant = kbSize.height + 20; }else{ self.bottomCon.constant = kbSize.width + 20; } } -(void)keyboardDidShow:(NSNotification *) aNotificaation { [self.tv scrollRangeToVisible:NSMakeRange(self.tv.text.length - 1, 1)]; } - (void)keyboardWillHide:(NSNotification*)aNotification { self.bottomCon.constant = 20; } -(IBAction)finishedEditing:(id)sender { // action for "Done" button on tool bar [self.tv resignFirstResponder]; } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

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