Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
639 views
in Technique[技术] by (71.8m points)

cocoa touch - Can UIScrollView's deceleration rate be modified?

Since this question was originally asked, UIScrollView deceleration rate customization has been added via the decelerationRate property introduced in OS 3.0.


I have a UIScrollView whose deceleration rate I'd like to change. To be clear, I'm talking about when you swipe your finger on a scroll view and the view continues to scroll (but gradually slows) after you lift your finger. I'd like to increase the deceleration rate so that it stops sooner that it does by default.

I've seen some apps where the UIScrollViews seem to decelerate more quickly. There seems to be no API for this in UIScrollView, but I'm wondering if there's an alternative way to do it.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You can use UIScrollView's decelerationRate property to control it. Even though its float, its not accepting any value other than UIScrollViewDecelerationRateNormal or UIScrollViewDecelerationRateFast . Look at the following code

NSLog(@"1. decelerationRate %f", scrollview.decelerationRate);

scrollview.decelerationRate = UIScrollViewDecelerationRateNormal;
NSLog(@"2. decelerationRate %f", scrollview.decelerationRate);

scrollview.decelerationRate = UIScrollViewDecelerationRateFast;
NSLog(@"3. decelerationRate %f", scrollview.decelerationRate);

scrollview.decelerationRate = 0.7;
NSLog(@"4. decelerationRate %f", scrollview.decelerationRate);

scrollview.decelerationRate = 0.995;
NSLog(@"5. decelerationRate %f", scrollview.decelerationRate);

Above code gives the following outputs, its very clear we cant not use custom deceleration rate.

2012-01-03 11:59:41.164 testviewv2[10023:707] 1. decelerationRate 0.998000
2012-01-03 11:59:41.172 testviewv2[10023:707] 2. decelerationRate 0.998000
2012-01-03 11:59:41.173 testviewv2[10023:707] 3. decelerationRate 0.990000
2012-01-03 11:59:41.175 testviewv2[10023:707] 4. decelerationRate 0.990000
2012-01-03 11:59:41.176 testviewv2[10023:707] 5. decelerationRate 0.998000

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...