Can UIScrollView's deceleration rate be modified?

前端 未结 5 702
失恋的感觉
失恋的感觉 2020-12-14 01:36

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

5条回答
  •  自闭症患者
    2020-12-14 02:21

    There is a pretty straightforward approach. Override the setter method.

    @interface UIArbitraryDeceleratingScrollView : UIScrollView
    
    @property(nonatomic,assign) CGFloat decelerationRate;
    
    @end
    
    @implementation UIArbitraryDeceleratingScrollView
    
    @synthesize decelerationRate = _decelerationRate;
    
    - (void)setDecelerationRate:(CGFloat)dr
    {
        [super setDecelerationRate:dr];
        _decelerationRate = dr;
    }
    
    @end
    

    Now assign what you want to, like this for example:

    _scroller.decelerationRate = (UIScrollViewDecelerationRateNormal+UIScrollViewDecelerationRateFast)/2.1;
    

提交回复
热议问题