Note that there are some explanatory texts on larger screens.

plurals
  1. POiPhone - How may I scroll a UITextField and resize a UITextView when keybord appears
    primarykey
    data
    text
    <p>I have a UIScrollView inside which I have a UITextField and a UITextView. I want to prevent the keyboard to hide the field we are working on. If my user tap on the TextField, I want it to scroll to top of the screen. If my user tap on the TextView, I want it to resize to the empty place left on the top of the keyboard. My keyboard has an accessory view (a toolbar).</p> <p>For now, I catch the UIKeyboardWillShowNotification notification, and I use this code, that does not really work (the textview is resized, but is still behind the keyboard) : This code worked well when I hadn't the UIScrollView.</p> <pre><code>- (void)keyboardWillShow:(NSNotification *)notification { if ([self.noteView isFirstResponder] == NO) return; /* Reduce the size of the text view so that it's not obscured by the keyboard. Animate the resize so that it's in sync with the appearance of the keyboard. */ NSDictionary *userInfo = [notification userInfo]; NSValue* aValue = [userInfo objectForKey:UIKeyboardFrameEndUserInfoKey]; // Get the origin of the keyboard when it's displayed. NSValue *animationDurationValue = [userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey]; // Get the duration of the animation. // Get the top of the keyboard as the y coordinate of its origin in self's view's coordinate system. The bottom of the text view's frame should align with the top of the keyboard's final position. CGRect keyboardRect = [aValue CGRectValue]; keyboardRect = [self.view convertRect:keyboardRect fromView:nil]; CGFloat keyboardTop = keyboardRect.origin.y; CGRect newTextViewFrame = self.view.bounds; newTextViewFrame.size.height = keyboardTop - self.view.frame.origin.y; // Using bounds here does not help NSTimeInterval animationDuration; [animationDurationValue getValue:&amp;animationDuration]; // Animate the resize of the text view's frame in sync with the keyboard's appearance. [UIView beginAnimations:nil context:NULL]; [UIView setAnimationDuration:animationDuration]; self.noteView.frame = newTextViewFrame; [UIView commitAnimations]; } </code></pre> <p>So could you help me to :</p> <ul> <li><p>make this work for the textview ?</p></li> <li><p>make the Textview go back to its original position ?</p></li> <li><p>How may I do to scroll the TextField without any resizing feature ?</p></li> </ul> <p>Thank you</p>
    singulars
    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. 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