Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>First set your content over a scroll view and set the scroll view in viewDidLoad:</p> <pre><code>[scrollView setContentSize : CGSizeMake (320, 1040)]; </code></pre> <p>then in viewWillAppear add following notification :</p> <p>For keyboard shown</p> <pre><code>[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWasShown:) name:UIKeyboardDidShowNotification object:nil]; </code></pre> <p>For keyboard hiding</p> <pre><code>[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillBeHidden:) name:UIKeyboardWillHideNotification object:nil]; </code></pre> <p>Following are the two function which are called by the notifications</p> <pre><code>- (void)keyboardWasShown:(NSNotification*)aNotification { NSDictionary* info = [aNotification userInfo]; CGSize kbSize = [[info objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size; double keyboardHeight = kbSize.height; double screenHeight = [UIScreen mainScreen].bounds.size.height - 20; if(textOrigin &gt; screenHeight - keyboardHeight) { double sofset = textOrigin - (screenHeight - keyboardHeight); CGPoint offset = scrollBackGround.contentOffset; offset.y += sofset; [scrollBackGround setContentOffset:offset animated:YES]; } } - (void)keyboardWillBeHidden:(NSNotification*)aNotification { [scrollBackGround setContentOffset:CGPointMake(0, 0) animated:YES]; } </code></pre> <p>In keyboardWasShown function what we are doing is just getting the height of the keyboard and checking if the textField y axis (i.e textOrigin in the function) are greater than Y axis of keyboard than slide up the content of the scrollview which contain our text field.</p> <p>NOw How to get the textfield Y axis. For this you have to use the textfield delegate, the following delegate will trigger when your textfield will become first responder</p> <pre><code>- (void)textFieldDidBeginEditing:(UITextField *)textField { textOrigin = scrollBackGround.frame.origin.y + textField.frame.origin.y + 20(it is status bar height) + yourNavigationBarheight; // Make sure to make textOrigin an ivar in your .h file } </code></pre> <p>And finally in keyboardWillBeHidden we are reseting the scrollview contentview</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.
    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