views:

844

answers:

1

I have a UIScrollView with a few UITextFields on it. When the user edits a text field it scrolls so that the UITextField is centered. The problem I am running into is that the UIScrollView is scrolling to the correct spot but at the last frame of the animation it is jumps to 300,300. It works fine in 2.2.1 but not in 3.0 beta 5. It always jumps to exactly 300,300 too. The strange thing is that when I call the returnScrollAfterEdit method that moves the scroll view the same way it works just fine. Any ideas what could cause this?

- (void)scrollViewToCenterOfScreen:(UIView *)field withKeyboard:(bool)withKeyboard {
    CGFloat viewCenterY = field.center.y;  
    CGRect applicationFrame = [[UIScreen mainScreen] applicationFrame];
    CGFloat availableHeight = applicationFrame.size.height - 215;

    CGFloat y = viewCenterY - availableHeight / 2.0;

    NSLog([NSString stringWithFormat:@"w:%f h%f availH:%f y:%f x:%f", applicationFrame.size.width, applicationFrame.size.height, availableHeight, y, self.contentOffset.x]);

    if (y 
A: 

I'm not sure if this is exactly what you are looking for but I had some crazy issues with UITextView as well. It would scroll to the bottom of the frame if I had selected any text in the view. I fixed this by turning off the scrollEnabled before adding the text to the UITextView.

So the code would look something like this:

[textarea setText:@""]; //blank out the text to scroll back to the top
[textarea setScrollEnabled:NO]; //disable to avoid scrolling
[textarea setText:@"new text here"]; 
[textarea setScrollEnabled:YES];
[textarea resignFirstResponder]; //to drop annoying blue

I hope this helps.

Kevin Beck
I ended up changing the GUI to avoid this, but I will give it a try next time I run into it.
Kevin