UIScrollView的减速率可以修改吗? [英] Can UIScrollView's deceleration rate be modified?

查看:329
本文介绍了UIScrollView的减速率可以修改吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于此问题最初提出,UIScrollView减速率自定义已通过 decelerationRate属性






我有一个UIScrollView的减速率我想改变。为了清楚起见,我说的是当你在滚动视图上滑动手指时,抬起手指后视图继续滚动(但逐渐减慢)。



我看到一些应用程序,其中的UIScrollViews似乎减速更快。我想要​​增加减速率,以便它在默认情况下停止。在UIScrollView中似乎没有这个API,但我想知道是否有另一种方法来做。

解决方案

您可以使用 UIScrollView decelerationRate 属性以控制它。即使其浮动,它不接受任何值除了UIScrollViewDecelerationRateNormal或UIScrollViewDecelerationRateFast 。查看以下代码

  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);

上面的代码给出了以下输出,很清楚,我们不能使用自定义减速率。

  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
pre>

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.

解决方案

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

这篇关于UIScrollView的减速率可以修改吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆