IPhone Auto-scroll UITextView but allow manual scrolling also?

You could just make it move relative to where it is.

Up vote 2 down vote favorite 3 share g+ share fb share tw.

I have a UITextView that has a lot of content. I have a button that allows the UITextView to automatically scroll + 10 pixels in an NSTimer loop: scrollPoint = CGPointMake(scrollPoint. X, scrollPoint.

Y + 10); textView setContentOffset:scrollPoint animated:YES; This works really well, as the animation makes the scroll rather smooth. I want to allow the user to skip ahead or back by scrolling with their finger, however due to this code after the scroll animation, the scroll snaps back to where it would have auto-scrolled. I need to reset the scrollPoint variable after a manual scroll, but I'm not sure how to do that.

I've tried implementing the delegate method - (void)scrollViewDidEndScrollingAnimation:(UIScrollView *)scrollView; but this method fires on my automatic scroll as well. Any ideas? Iphone iphone-sdk-3.0 uiscrollview uitextview link|improve this question asked Jul 6 '09 at 20:05Ben Scheirman16.4k53880 81% accept rate.

You could just make it move relative to where it is: scrollPoint = textView. ContentOffset; scrollPoint. Y= scrollPoint.

Y+10; textView setContentOffset:scrollPoint animated:YES.

Man I had my head WAY too close to this problem. Your solution works beautifully! Thanks.

– Ben Scheirman Jul 6 '09 at 23:17.

I think by having effectively 2 ways to scroll the content your kind of fighting the API. If I understand correctly, in your current setup you have a button that fires an animation. When you scroll in this way, an animation is created and run on another thread.

While the animation is running, the presentation layer is being changed. However, the actual content offset is NOT set until the animation completes. This works fine and transparently, until you attempt to animate the same property while it is already being animated.

Normally, in this case you cancel the existing animations, set the frame to the presentation layer (current onscreen position), then apply the new animation. However, you are using a convenience method of the textView (setContentOffset:animated:). When you do this you give up fine animation control, in exchange for less lines of code.

I think that stopping a scroll in progress may be hard, or impossible using the higher level APIs. This means to do what you want you would at least have to try a UIView animation block and most likely actually create a CAAnimation. The easier solution is to settle on one means of scrolling your textView.

The HIG favors using direct manipulation on the iPhone. Even if it is easy to perform the scroll both ways, I would recommend ditching the button method, and just use the direct manipulation you are now implementing.

I wanted to do the same thing you are trying to do Ben, but I found that the animation was too costly in terms of display time and seemed to defeat the purpose. I played around with it and found the following code does exactly what you wanted it to do and doesn't bog down the system at all. Setup if (autoscrollTimer == nil) { autoscrollTimer = NSTimer scheduledTimerWithTimeInterval:(35.0/1000.0) target:self selector:@selector(autoscrollTimerFired:) userInfo:nil repeats:YES; } The key is in turning the animation OFF and moving the offset in smaller increments.

It seems to run faster and it doesn't interfere with the manual scroll. - (void)autoscrollTimerFired:(NSTimer*)timer { CGPoint scrollPoint = self.textView. ContentOffset; scrollPoint = CGPointMake(scrollPoint.

X, scrollPoint. Y + 1); self. TextView setContentOffset:scrollPoint animated:NO; } I am pretty new to objective-c and iphone development so if anybody with more experience sees a problem with this approach I would appreciate any feedback.

In my case I really liked the animation, but if you're only moving by 1 pixel then it should be smooth. For other reasons, though, I switched to using a webView, which doesn't inherit from Scroll View, so I had to use Javascript to do the scrolling. Yuck.

It was slightly choppy, but it was a worthwhile tradeoff. – Ben Scheirman Jul 13 '10 at 15:44.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions