有人能够正确地做到这一点吗?
这是一个涵盖手势http://www.raywenderlich.com/22174/how-to-make-a-gesture-driven-to-do-list-app-part-33的教程。以下是项目文件:https://github.com/ColinEberhardt/iOS-ClearStyle
它远不如原始的Clear应用程序那么顺畅:
#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