Can UIScrollView's deceleration rate be modified?

前端 未结 5 691
失恋的感觉
失恋的感觉 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:29

    I found that by using KVC to modify the instance variable _decelerationFactor allowed me to change the rate to something other than UIScrollViewDecelerationRateNormal or UIScrollViewDecelerationRateFast. I subclassed UIScrollView and wrapped the whole lot in a try block

    - (id)initWithFrame:(CGRect)frame
    {
        self = [super initWithFrame:frame];
        if (self) {
            // Initialization code
            @try {
                CGFloat decelerationRate = UIScrollViewDecelerationRateFast +(UIScrollViewDecelerationRateNormal - UIScrollViewDecelerationRateFast) * .52;
                [self setValue:[NSValue valueWithCGSize:CGSizeMake(decelerationRate,decelerationRate)] forKey:@"_decelerationFactor"];
    
            }
            @catch (NSException *exception) {
                // if they modify the way it works under us.
            }
    
    
        }
        return self;
    }
    

提交回复
热议问题