Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The best result was reached by the following code. Also don't forget to set background color to <code>UIView</code> and place <code>UITextView</code> <strong>before</strong> other top-screen controls (e.g. UITabBar).</p> <p>Editing of a text in the end still isn't perfect now. You may try to improve.</p> <p><code>FirstViewController.h:</code></p> <pre><code>@interface FirstViewController : UIViewController { IBOutlet UIBarButtonItem *buttonDone; IBOutlet UITextView *textView; UITabBarController* tabBarController; // set from superview in AppDelegate (MainWindow.xib) } @property (nonatomic, retain) UITabBarController* tabBarController; </code></pre> <p><code>FirstViewController.m:</code></p> <pre><code>@synthesize tabBarController; - (void)viewDidAppear:(BOOL)animated { [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShown:) name:UIKeyboardWillShowNotification object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil]; } - (void)viewWillDisappear:(BOOL)animated { [[NSNotificationCenter defaultCenter] removeObserver:self]; } - (void)moveTextViewForKeyboard:(NSNotification*)aNotification up:(BOOL)up { NSDictionary* userInfo = [aNotification userInfo]; NSTimeInterval animationDuration; UIViewAnimationCurve animationCurve; CGRect keyboardEndFrame; [[userInfo objectForKey:UIKeyboardAnimationCurveUserInfoKey] getValue:&amp;animationCurve]; [[userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey] getValue:&amp;animationDuration]; [[userInfo objectForKey:UIKeyboardFrameEndUserInfoKey] getValue:&amp;keyboardEndFrame]; [UIView beginAnimations:nil context:nil]; [UIView setAnimationDuration:animationDuration]; [UIView setAnimationCurve:animationCurve]; CGRect newFrame = textView.frame; CGRect keyboardFrame = [self.view convertRect:keyboardEndFrame toView:nil]; keyboardFrame.size.height -= tabBarController.tabBar.frame.size.height; newFrame.size.height -= keyboardFrame.size.height * (up?1:-1); textView.frame = newFrame; [UIView commitAnimations]; } - (void)keyboardWillShown:(NSNotification*)aNotification { buttonDone.enabled = true; [self moveTextViewForKeyboard:aNotification up:YES]; } - (void)keyboardWillHide:(NSNotification*)aNotification { buttonDone.enabled = false; [self moveTextViewForKeyboard:aNotification up:NO]; } </code></pre> <p>P.S. It's hard to code for iOS without stackoverflow...</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