Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I've found the easiest solution to be this one(I'm not fan of using subviews for this kind of stuff):</p> <p>register for keyboard frame change notification(idealy register in viewWillAppear: and unregister in viewWillDisappear:):</p> <pre><code>[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardDidChangeFrame:) name:UIKeyboardDidChangeFrameNotification object:nil]; </code></pre> <p>and then in method:</p> <pre><code>- (void)keyboardDidChangeFrame:(NSNotification*)aNotification { NSDictionary* info = [aNotification userInfo]; UIWindow *window = [[[UIApplication sharedApplication] delegate] window]; CGRect kbFrame = [[info objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue]; CGRect kbIntersectFrame = [window convertRect:CGRectIntersection(window.frame, kbFrame) toView:self.scrollView]; kbIntersectFrame = CGRectIntersection(self.bounds, kbIntersectFrame); UIEdgeInsets contentInsets = UIEdgeInsetsMake(0.0, 0.0, kbIntersectFrame.size.height, 0.0); self.scrollView.contentInset = contentInsets; self.scrollView.scrollIndicatorInsets = contentInsets; } </code></pre> <p>or if You want to get rid of the "jump" after changing contentInset:</p> <pre><code>- (void)keyboardDidChangeFrame:(NSNotification*)aNotification { NSDictionary* info = [aNotification userInfo]; UIWindow *window = [[[UIApplication sharedApplication] delegate] window]; CGRect kbFrame = [[info objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue]; CGRect kbIntersectFrame = [window convertRect:CGRectIntersection(window.frame, kbFrame) toView:self.scrollView]; kbIntersectFrame = CGRectIntersection(self.scrollView.bounds, kbIntersectFrame); // get point before contentInset change CGPoint pointBefore = self.scrollView.contentOffset; UIEdgeInsets contentInsets = UIEdgeInsetsMake(0.0, 0.0, kbIntersectFrame.size.height, 0.0); self.scrollView.contentInset = contentInsets; self.scrollView.scrollIndicatorInsets = contentInsets; // get point after contentInset change CGPoint pointAfter = self.scrollView.contentOffset; // avoid jump by settings contentOffset self.scrollView.contentOffset = pointBefore; // and now animate smoothly [self.scrollView setContentOffset:pointAfter animated:YES]; } </code></pre>
    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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      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