美文网首页
使用MJRefresh第三方库时遇到的问题

使用MJRefresh第三方库时遇到的问题

作者: 开发者zhang | 来源:发表于2017-11-07 21:03 被阅读0次

问题:设置好下拉刷新控件后测试,发现瞬间刷新并且tableview在下拉放手的时候快速弹回状态栏背后。

原因:

苹果ios11新协议:MJRefresh在iOS11.0中稍微下拉触发瞬间刷新事件自iOS11.0和iPhone X发布以来iOSDeveloper都要学习苹果给的新协议,MJRefresh在iOS11.0中也不能幸免,手势触摸屏幕,稍微下拉就会触发下拉刷新事件

@property(nonatomic,assign) BOOL automaticallyAdjustsScrollViewInsets API_DEPRECATED_WITH_REPLACEMENT("Use UIScrollView's contentInsetAdjustmentBehavior instead", ios(7.0,11.0),tvos(7.0,11.0)); // Defaults to YES

iOS11.0也弃用了automaticallyAdjustsScrollViewInsets。

解决方法:

//状态栏和导航栏
    CGRect rectStatus = [[UIApplication sharedApplication] statusBarFrame];
    CGRect rectNav = self.navigationController.navigationBar.frame;
    
    //设置头部
    if (@available(iOS 11.0, *)) {
        self.tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
    } else {
        self.automaticallyAdjustsScrollViewInsets = NO;
    }
    self.tableView.contentInset = UIEdgeInsetsMake(rectStatus.size.height + rectNav.size.height, 0, 0, 0);
    self.tableView.scrollIndicatorInsets = self.tableView.contentInset;
    
    // 下拉刷新
    tableView.mj_header= [MJRefreshNormalHeader headerWithRefreshingBlock:^{
        [self loadTodayData];
        // 结束刷新
        [tableView.mj_header endRefreshing];
    }];

相关文章

网友评论

      本文标题:使用MJRefresh第三方库时遇到的问题

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