I have a problem with what almost looks like a bug in iOS. I am trying to do a simple scroll in a UIScrollView. If I go to the point with the animation, it scrolls fine there, but it does not set the point in scrollView. I.E. when I move to another place later, it jumps to 0.0 and starts the animation from there.
I am using the following code
[scrollView setContentOffset:CGPointMake(0, 95) animated:YES];
NSLog(@"offset x %@", [[NSNumber numberWithFloat:scrollView.contentOffset.x] stringValue]);
NSLog(@"offset y %@", [[NSNumber numberWithFloat:scrollView.contentOffset.y] stringValue]);
which produces the output
offset x 0
offset y 0
while the same code with animation disabled:
[scrollView setContentOffset:CGPointMake(0, 95) animated:NO];
NSLog(@"offset x %@", [[NSNumber numberWithFloat:scrollView.contentOffset.x] stringValue]);
NSLog(@"offset y %@", [[NSNumber numberWithFloat:scrollView.contentOffset.y] stringValue]);
outputs a conclusion
offset x 0
offset y 95
I'm trying to automatically scroll to a UITextView, so I listen to some keyboard notifications, where I usually scroll. But I did this test in viewDidLoad, and it produces these results.
scrollView.contentOffset = CGPointMake (0,95); . , .
:
, , :
- (void)textFieldDidBeginEditing:(UITextField *)textField {
[self.scrollView setContentOffset:CGPointMake(0, textField.frame.origin.y-60) animated:YES];
}
. , , contentOffset, 0,0 . , .