自定义的上拉加载更多

发布时间:2016-12-9 11:59:08 编辑:www.fx114.net 分享查询网我要评论
本篇文章主要介绍了"自定义的上拉加载更多",主要涉及到自定义的上拉加载更多方面的内容,对于自定义的上拉加载更多感兴趣的同学可以参考一下。

//加载更多 _moreButton = [UIButton buttonWithType:UIButtonTypeCustom]; _moreButton.backgroundColor = [UIColor clearColor]; _moreButton.frame = CGRectMake(0, 0, kScreenWidth, 40); _moreButton.titleLabel.font = [UIFont systemFontOfSize:15]; [_moreButton setTitle:@"上拉加载更多..." forState:UIControlStateNormal]; [_moreButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal]; [_moreButton addTarget:self action:@selector(loadMoreAction) forControlEvents:UIControlEventTouchUpInside]; UIActivityIndicatorView *activityView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray]; activityView.frame = CGRectMake(100, 10, 20, 20); activityView.tag = 2000; [activityView stopAnimating]; [_moreButton addSubview:activityView]; [activityView release]; self.tableFooterView = _moreButton; //加载更多 -(void)loadMoreAction { //如果没有更多,就返回 if (!self.isMore) { return; } if (_pullUpBlock) { //刷新正在加载的状态 [self startLoadMore]; //执行上拉的操作 _pullUpBlock(self); } } -(void)startLoadMore { [_moreButton setTitle:@"正在加载.." forState:UIControlStateNormal]; _moreButton.enabled = NO; UIActivityIndicatorView *activityView = (UIActivityIndicatorView *)[_moreButton viewWithTag:2000]; [activityView startAnimating]; } -(void)stopLoadMore { if (self.data.count > 0) { _moreButton.hidden = NO; _moreButton.enabled = YES; [_moreButton setTitle:@"上拉加载更多..." forState:UIControlStateNormal]; UIActivityIndicatorView *activityView = (UIActivityIndicatorView *)[_moreButton viewWithTag:2000]; [activityView stopAnimating]; //加载完成,如果没有更多的数据,则也隐藏 if (!self.isMore) { _moreButton.hidden = YES; } }else{ _moreButton.hidden = YES; } } //重写reloadData方法 -(void)reloadData { [super reloadData]; //停止加载更多 [self stopLoadMore]; } #pragma mark - #pragma mark UIScrollViewDelegate Methods - (void)scrollViewDidScroll:(UIScrollView *)scrollView{ [_refreshHeaderView egoRefreshScrollViewDidScroll:scrollView]; } - (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate{ [_refreshHeaderView egoRefreshScrollViewDidEndDragging:scrollView]; //-------- 上拉加载更多 ------- //实现原理: contentOffset.height + height = contentSize.height //y坐标滚动的偏移量 float offset = scrollView.contentOffset.y; //scrollView的内容高度 float contentHeight = scrollView.contentSize.height; //当offset偏移量滑到底部时,差值是scrollView的高度 float sub = contentHeight-offset; // float sub = scrollView.contentSize.height-scrollView.contentOffset.y; if (scrollView.height - sub > 50) { [self loadMoreAction]; } } #pragma mark - #pragma mark EGORefreshTableHeaderDelegate Methods //已经触发了下拉刷新 - (void)egoRefreshTableHeaderDidTriggerRefresh:(EGORefreshTableHeaderView*)view{ //刷新数据 [self reloadTableViewDataSource]; //刷新数据 if (_pullDownBlock) { _pullDownBlock(self); } // //模拟 停止加载,弹回下拉 // [self performSelector:@selector(doneLoadingTableViewData) withObject:nil afterDelay:1.0]; } - (BOOL)egoRefreshTableHeaderDataSourceIsLoading:(EGORefreshTableHeaderView*)view{ return _reloading; // should return if data source model is reloading } //取得下拉刷新的时间 - (NSDate*)egoRefreshTableHeaderDataSourceLastUpdated:(EGORefreshTableHeaderView*)view{ return [NSDate date]; // should return date data source was last changed }

上一篇:s3c6410芯片
下一篇:[email protected]

相关文章

相关评论