美文网首页
置顶按钮(tableview)

置顶按钮(tableview)

作者: 筱笑 | 来源:发表于2018-08-29 13:52 被阅读20次

    列表数据滑动之后,显示置顶按钮(tableView存在分页)
    点击置顶按钮之后,列表数据回到最上一行

    #define WD_TabBarHeight ([[UIApplication sharedApplication] statusBarFrame].size.height>20?83:49) //底部tabbar高度
    
    @property(nonatomic,strong) UITableView *debitTable;
    @property (nonatomic, strong) UIButton * backTopBtn;//置顶按钮
    
    #pragma mark 创建置顶按钮
    -(void)createBackTopBtn{
        self.backTopBtn = [UIButton  buttonWithType:UIButtonTypeCustom];
        [self.backTopBtn setBackgroundImage:[UIImage imageNamed:@"zhiding"] forState:UIControlStateNormal];
        [self.backTopBtn addTarget:self action:@selector(backTopOffset) forControlEvents:UIControlEventTouchUpInside];
        [self.view addSubview:self.backTopBtn];
        [self.backTopBtn mas_makeConstraints:^(MASConstraintMaker *make) {
              make.bottom.mas_equalTo(self.view).offset(-25-WD_TabBarHeight);
              make.right.mas_equalTo(self.view).offset(-15);
              make.width.mas_equalTo(48.5);
              make.height.mas_equalTo(48.5);
         }];
        self.backTopBtn.hidden = YES;
    }
    - (void)backTopOffset {
        NSIndexPath* indexPat = [NSIndexPath indexPathForRow:0 inSection:0];
        [self.debitTable scrollToRowAtIndexPath:indexPat atScrollPosition:UITableViewScrollPositionBottom animated:YES];
    }
    
    #pragma mark - 置顶按钮的显示隐藏
    - (void)scrollViewDidScroll:(UIScrollView *)scrollView {
        if (scrollView == self.debitTable) {
            if (self.debitTable.contentOffset.y > 0) {
                self.backTopBtn.hidden = NO;
            }else {
                self.backTopBtn.hidden = YES;
            }
        }
    }
    
    [图片上传中...(zhiding@3x.png-31bd87-1535521886644-0)]

    相关文章

      网友评论

          本文标题:置顶按钮(tableview)

          本文链接:https://www.haomeiwen.com/subject/bvmhwftx.html