//置顶点击事件
- (IBAction)topClick:(UIButton *)sender {
//回到顶部
[self.tableView setContentOffset:CGPointMake(0, 20) animated:YES];
[self.tableView scrollRectToVisible:CGRectMake(0, 0, 1, 1) animated:NO];
[self.tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0] atScrollPosition:UITableViewScrollPositionTop animated:YES];
- (IBAction)topClick:(UIButton *)sender {
//回到顶部
[self.tableView setContentOffset:CGPointMake(0, 20) animated:YES];
[self.tableView scrollRectToVisible:CGRectMake(0, 0, 1, 1) animated:NO];
[self.tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0] atScrollPosition:UITableViewScrollPositionTop animated:YES];
}
//滚完监听
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
if (self.tableView.contentOffset.y > 0) {
self.topBtn.hidden = NO;
} else {
self.topBtn.hidden = YES;
}
}
//滚时监听
- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate {
if (self.tableView.contentOffset.y > 0) {
self.topBtn.hidden = NO;
} else {
self.topBtn.hidden = YES;
}
}