I was wonder how snapchat animates that ghost thing when you pull down to refresh? I wanted to implement that in my app and was wondering how it was done.
问问题
2009 次
1 回答
7
我认为您需要编写自己的解决方案。但这真的没那么难。
您需要创建一个包含可拉伸图像的自定义表头视图,并在UITableViewDelegate
. 下面是自定义刷新控件处理的一个相当通用的实现。
1)创建一个自定义 UIView 作为您的下拉指示器视图:
头文件:
#import <UIKit/UIKit.h>
typedef enum UpdateListViewState
{
UpdateListViewStatePull,
UpdateListViewStateRelease,
UpdateListViewStateUpdate
}UpdateListViewState;
@interface UpdateListView : UIView
@property (nonatomic,readwrite) UpdateListViewState state;
@property (nonatomic,strong) UIImageView imageView;
@end
2)将 headerView 分配为 tableView 标题:
self.header = [[UpdateListView alloc] init];
self.table.tableHeaderView = self.header;
3)在你的UITableViewDelegate
,实现表格滚动处理:
const int UPDATE_DRAG_HEIGHT = -70;
- (void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset
{
if (self.header.state == UpdateListViewStateRelease) {
//Perform update stuff here & perhaps refresh animation
self.header.state = UpdateListViewStateInitial;
}
}
-(void)scrollViewDidScroll:(UIScrollView *)scrollView
{
//adjust size of self.header.imageView here according to scrollView.ContentOffset
if (scrollView.contentOffset.y < UPDATE_DRAG_HEIGHT && self.header.state != UpdateListViewStateUpdate) {
self.header.state = UpdateListViewStateRelease;
}
}
于 2013-08-19T13:49:03.023 回答