In the context of the iPhone:
I have a UIScrollView
containing a UIImage
. When the user taps the screen inside the UIImage
, a
Basically setFrame
of UIScrollView
will readjust the scrollview offset
, done by _adjustContentOffsetIfNecessary
. As that method is private and not documented, there is very little we can guess on how the adjustment will happen.
There are two ways to stop the unnecessary scrolling or wrong offset
being set:
1) reset the UIScrollView
offset
after applying setFrame
. This you can do, if you are modifying the frame of UIScrollView
intentionally based on some calculations.
CGPoint oldOffset = [scrollView contentOffset];
scrollView.frame = CGRectMake(newFrame);
[scrollView setContentOffset:oldOffset];
2) apply offset
changes without animation. In your keyboardWasShown
, change
[self setContentOffset:scrollPoint animated:YES]; to
[self setContentOffset:scrollPoint animated:NO];
Reason: when more than one offset
is applied with animation on, the result offset
is ambiguous. Here the internal method(_adjustContentOffsetIfNecessary
) applies an offset change and the other one is done by your code. You can notice this if you try to log all the offsets being applied in the UIScrollView
delegate method:
-(void)scrollViewDidScroll:(UIScrollView *)scrollView
{
NSLog(@" offset: %@", NSStringFromCGPoint(scrollView.conentOffset))
}
Let me know if this helps.