Wednesday, June 5, 2013

UIScrollView UIScrollViewDecelerationRateFast example in Objective C (iOS).


UIScrollView UIScrollViewDecelerationRateFast

Deceleration Constants
The rate of deceleration for a scrolling view.

const float UIScrollViewDecelerationRateNormal;
const float UIScrollViewDecelerationRateFast;

Constants
UIScrollViewDecelerationRateNormal
The default deceleration rate for a scroll view.
UIScrollViewDecelerationRateFast
A fast deceleration rate for a scroll view.

UIScrollView UIScrollViewDecelerationRateFast example.
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);

Example of [UIScrollView UIScrollViewDecelerationRateFast].
- (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;
}

UIScrollView UIScrollViewDecelerationRateFast example.
You can just turn up the deceleration rate very high. With an infinite rate, it would stop immediately. Try setting the rate to these constants:

scrollView.decelerationRate = UIScrollViewDecelerationRateNormal;
and

scrollView.decelerationRate = UIScrollViewDecelerationRateFast;

End of UIScrollView UIScrollViewDecelerationRateFast example article.