I know how to get the contentOffset on movement for a UIScrollView, can someone explain to me how I can get an actual number that represents the current speed of a UIScrollView while it is tracking, or decelerating?
相关问题
- CALayer - backgroundColor flipped?
- Core Data lightweight migration crashes after App
- How can I implement password recovery in an iPhone
- how do you prevent page scroll in textarea on mobi
- Custom UITableview cell accessibility not working
相关文章
- UITableView dragging distance with UIRefreshContro
- Could I create “Call” button in HTML 5 IPhone appl
- Unable to process app at this time due to a genera
- How do you detect key up / key down events from a
- “Storyboard.storyboard” could not be opened
- Open iOS 11 Files app via URL Scheme or some other
- Can keyboard of type UIKeyboardTypeNamePhonePad be
- SwiftUI automatically scroll to bottom in ScrollVi
Converted @bandejapaisa answer to Swift 2.2:
Properties used by UIScrollViewDelegate:
And the scrollViewDidScroll function:
May be this would be helpful
2017...
It's very easy to do this with modern Swift/iOS:
Of course you want the velocity in points per second, which is what that is.
Humans drag at say 200 - 400 pps (on 2017 devices).
1000 - 3000 is a fast throw.
As it slows down to a stop, 20 - 30 is common.
So very often you will see code like this ..
This is the basis for "skimming engineering" on mobiles. (Which is a large and difficult topic.)
Note that that is not a complete skimming solution; you also have to care for unusual cases like "it has stopped" "the screen just closed" etc etc.
You can see PageControl sample code about how to get the contentOffset of scrollview.
The
contentOffset
on movement can be obtained fromUIScrollViewDelegate
method, named- (void)scrollViewDidScroll:(UIScrollView *)scrollView
, by queryingscrollView.contentOffset
. Current speed can be calculated by delta_offset and delta_time.Have these properties on your UIScrollViewDelegate
Then have this code for your scrollViewDidScroll:
And from this i'm getting pixels per millisecond, which if is greater than 0.5, i've logged as fast, and anything below is logged as slow.
I use this for loading some cells on a table view animated. It doesn't scroll so well if I load them when the user is scrolling fast.
Here is another smart way to do this in SWIFT :-
So if you scrolling vertically you should use velocity.y and also if you are scrolling horizontally you should use velocity.x . Generally if value is more than 1 and less than -1, it represent generally fast scrolling. So you can change the speed as you want. +value means scrolling up and -value means scrolling down.