My users are reading readonly text in a UITextView. When they have finished reading a selection and have scrolled to the bottom, I would like to be able to display a Completed Reading button that animates up from the bottom. How can I detect when the user has scrolled to the end of the text?
Asked
Active
Viewed 402 times
1
-
Did you try this: http://stackoverflow.com/questions/13969970/detect-uitextview-scroll-location ? – ujell Jun 12 '14 at 06:50
-
1`UITextView` extends `UIScrollView`. Make use of the scrollview delegates to know when it has scrolled to the bottom. – rmaddy Jun 12 '14 at 06:56
-
Sorry, -scrollViewDidEndDecelerating does work better than -scrollViewDidScroll but it also fires if the user scrolls back up and so I need a way to discern if the text that is visible is actually the last part of the text. I've tried using a non-visible end_marker_string but it's searching all of the text instead of just the text that is visible. – kelly Jun 12 '14 at 15:32
-
@ujell - Yes. I had not seen that question but I have tried that method. I'm not sure why they said that it worked for them. When I used it, the NSLog statement was printed every time so this method of seeing if you are at the bottom does not work. I tried it again to make sure. Thanks. – kelly Jun 12 '14 at 15:34
-
I'm using this code within -scrollViewDidEndDescelerating. I have a method that appends an ENDMARKERSTRING that is called by -viewDidLoad NSString * strVisibleText = [self visibleTextInTextView:self.textView]; if ([strVisibleText rangeOfString:END_MARKER_STRING].location == NSNotFound) { NSLog(@"string does not contain END_MARKER_STRING"); } else { NSLog(@"string contains END_MARKER_STRING"); } – kelly Jun 12 '14 at 15:45
1 Answers
2
Hey just add UIScrollViewDelegate and this provide's below method that would be called as scroll end reaches.
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView;
So give it a try and let me know if anything.

nikhil84
- 3,235
- 4
- 22
- 43
-
Thanks, that is the event that I am using because it fires less often that -scrollViewDidScroll but it also fires when the user scrolls back up so it is not, in itself, a reliable way to know if you are the end of the text in the textView. – kelly Jun 12 '14 at 15:37
-
I was wrong! I had some other noise in my NSLogs that made me think it was firing twice but when I removed them, this turned out to be a perfectly clean solution. Thank you, marking as correct :) – kelly Jun 12 '14 at 16:10
-
3Within the method, in case anyone else needs it: //determines if user has scrolled to the bottom if (scrollView.contentOffset.y >= scrollView.contentSize.height - scrollView.frame.size.height) { NSLog(@"at bottom"); } – kelly Jun 12 '14 at 16:20