Note that there are some explanatory texts on larger screens.

plurals
  1. POiOS scrollView setContentOffset "shimmy"
    primarykey
    data
    text
    <p>I have a scrollView with multiple textFields, which tracks the active field and makes sure it is visible when the keyboard pops up. It all works well, but when I tab from the 3rd to 4th textField, I get a little up and down "shimmy" before the textField ends up in the right place. Any suggestions?</p> <pre><code>-(void)keyboardDidShow:(NSNotification *)notification { if (keyboardIsShown)return; NSDictionary* info=[notification userInfo]; // get keyboard size CGSize keyboardSize=[[info objectForKey:UIKeyboardFrameBeginUserInfoKey]CGRectValue].size; //Set scrollview insets to make room for keyboard UIEdgeInsets contentInsets=UIEdgeInsetsMake(0.0, 0.0, keyboardSize.height, 0.0); scrollView.contentInset=contentInsets; scrollView.scrollIndicatorInsets=contentInsets; //scroll the active text field into view CGRect viewFrame=self.view.frame; viewFrame.size.height-=keyboardSize.height; int fieldHeight=self.currentTextField.bounds.size.height; CGFloat navHeight=self.navigationController.navigationBar.frame.size.height; CGPoint viewPoint=CGPointMake(0.0, self.currentTextField.frame.origin.y+fieldHeight); if (!CGRectContainsPoint(viewFrame, viewPoint)) { //scroll to make sure active field is showing CGPoint scrollPoint=CGPointMake(0.0, viewPoint.y-keyboardSize.height+navHeight);//+navHeight [scrollView setContentOffset:scrollPoint animated:YES]; } } -(void)showActiveField { //this makes sure that activeField shows when selecting another field after initial keyboard show int fieldHeight=self.currentTextField.bounds.size.height; CGPoint viewPoint=CGPointMake(0.0, self.currentTextField.frame.origin.y+fieldHeight); CGRect viewFrame=self.view.frame; int inset=scrollView.contentInset.bottom; if (!CGRectContainsPoint(viewFrame, viewPoint)) { //scroll to make sure active field is showing CGPoint scrollPoint=CGPointMake(0.0, viewPoint.y-inset); [scrollView setContentOffset:scrollPoint animated:YES]; } } </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. 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