Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS

The Pull-to-Add Gesture as in Clear

Is anyone able to do this properly?

Here's a tutorial that covers the gesture http://www.raywenderlich.com/22174/how-to-make-a-gesture-driven-to-do-list-app-part-33. And here's the project files: https://github.com/ColinEberhardt/iOS-ClearStyle

It is far from as smooth as the original Clear app:

#pragma mark - UIScrollViewDelegate methods

- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
{
// this behaviour starts when a user pulls down while at the top of the table
_pullDownInProgress = scrollView.contentOffset.y <= 0.0f;

if (_pullDownInProgress)
{
    // add our placeholder
    [_tableView insertSubview:_placeholderCell atIndex:0];
}
}

- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
if (_pullDownInProgress && _tableView.scrollView.contentOffset.y <= 0.0f)
{
    // maintain the location of the placeholder
    _placeholderCell.frame = CGRectMake(0, - _tableView.scrollView.contentOffset.y - SHC_ROW_HEIGHT,
                                _tableView.frame.size.width, SHC_ROW_HEIGHT);
    _placeholderCell.label.text = -_tableView.scrollView.contentOffset.y > SHC_ROW_HEIGHT ?
                                                @"Release to Add Item" : @"Pull to Add Item";

    _placeholderCell.alpha = MIN(1.0f, - _tableView.scrollView.contentOffset.y / SHC_ROW_HEIGHT);
}
else
{
    _pullDownInProgress = false;
}
}

- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate
{
// check whether the user pulled down far enough
if (_pullDownInProgress && - _tableView.scrollView.contentOffset.y > SHC_ROW_HEIGHT)
{
    [_tableView.datasource itemAdded];
}

_pullDownInProgress = false;
[_placeholderCell removeFromSuperview];
}

@end

1 Answer

Sam Soffes
STAFF
Sam Soffes
Treehouse Guest Teacher

I use SSPullToRefresh in several projects. You might try checking out my version. It's pretty easy to get going.