Tuesday, June 4, 2013

UIScrollView decelerating example in Objective C (iOS).

UIScrollView decelerating

Returns whether the content is moving in the scroll view after the user lifted their finger. (read-only)

@property(nonatomic, readonly, getter=isDecelerating) BOOL decelerating

Discussion of [UIScrollView decelerating]
The returned value is YES if user isn't dragging the content but scrolling is still occurring.

UIScrollView decelerating example.
Assign a delegate to your UIScrollView object if you have not already done so.
In your delegate's .m implementation file, add the following lines of code:

-(void)scrollViewWillBeginDecelerating:(UIScrollView *)scrollView{ 
    [scrollView setContentOffset:scrollView.contentOffset animated:YES];  

Example of [UIScrollView decelerating].
if (self.tableView.isDecelerating) {
        NSArray *paths = [self.tableView indexPathsForVisibleRows];
        [self.tableView scrollToRowAtIndexPath:[paths objectAtIndex:0] atScrollPosition:UITableViewScrollPositionTop animated:NO];


UIScrollView decelerating example.
    -(void)scrollViewWillBeginDecelerating:(UIScrollView *)scrollView {
        [self.content setDecelerationRate:UIScrollViewDecelerationRateNormal];
        NSLog(@"scrollviewwillbegindecelerating %f", self.content.decelerationRate);

    -(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {

End of UIScrollView decelerating example article.