0
votes

I am trying to move my UIScrollView to make way for the keyboard when the keyboard is shown.

What's weird is the scrollview is moving too much. I noticed that if I even just set the content offset of the scrollview to (0,0) it still moves the view down. What's bizarre, is the contentOffset of the scrollview is 0,0 before I set it! Whattt!

- (void)keyboardWasShown:(NSNotification*)notification {
    NSLog(@"%f %f", scrollView.contentOffset.x, scrollView.contentOffset.x);
    [scrollView setContentOffset:CGPointMake(0.0, 0.0) animated:YES];
}

This prints (0,0) but if I comment the second line, the view doesn't move. Does setContentOffset have weird secondary consequences?

1
It calls scrollViewDidScroll, so maybe you are doing something there.Odrakir
@Odrakir nope didn't implement any other methodspfrank
Then post the code where you create the scrollView and set its content. Because that line by itself works.Odrakir

1 Answers

0
votes

Try this:

- (void)keyboardWasShown:(NSNotification*)notification {
CGFloat ay = 150;
[scrollView setContentOffset:CGPointMake(0.0, textField.frame.origin.y-ay) animated:YES];
}

Here change the value of ay as per your requirement. Depends on how much you want the scrollview to move.