Stop deceleration of UIScrollView
Asked Answered
E

1

18

What's the best way to immediately stop the deceleration of an UIScrollView in iPhone 3.0?

I would like to keep the deceleration of the UIScrollView until it naturally stops or the user performs a certain action, whatever happens first.

Thanks!

Entente answered 10/1, 2010 at 17:52 Comment(4)
Hi, are you sure that you want something like this? application behavior like this will be rejected by apple for sure.Reactor
Do you mean that after the user flicks the scroll view and it's scrolling along, you want to stop the view from scrolling in response to something else as though the user had put their finger down on it to stop it?Tap
Henrik: Yes. It shouldn't cause rejection in the context that I need it.Entente
Nimrod: Yes. Basically I want to stop the deceleration when the user presses a button that makes the interface change.Entente
R
16

Untested suggestion coming up:)

When the button tap event is caught, you read what the [scrollView contentOffset].x is, and set the offset to this value with animation OFF.

Rossman answered 10/1, 2010 at 23:15 Comment(3)
It works and seemed a non-hacky way of doing it. However, for some unknown reason it made the scroll indicators flash in the wrong place. The following code stops the deceleration and also avoids the aforementioned visual effect: myScrollView.showsHorizontalScrollIndicator = NO; myScrollView.showsVerticalScrollIndicator = NO; [myScrollView setContentOffset:myScrollView.contentOffset animated:NO]; myScrollView.showsHorizontalScrollIndicator = YES; myScrollView.showsVerticalScrollIndicator = YES; Ugly code.Entente
Glad it worked:) Does "scroll indicators flash in the wrong place" mean that the scrollbars were not at the right side and the bottom? I reckon you have [scrollView setPagingEnabled:YES]; and that this maybe could confuse the scrollView a bit. ScrollView :"The settings says scroll to next page and draw the scrollBars at coordinate x and y" You:"Stop what you are doing and figure out for your self where to draw the scrollbars!". I just did something similar where I made a scrollView that snapped to every 80 px, but I used animation:YES and that might give it a bit more time to adjust?Rossman
[scrollView setContentOffset:offset animated:NO] works for me in iOS 4.2.Deuce

© 2022 - 2024 — McMap. All rights reserved.