mjrefresh自动判断是否隐藏mj_footer

本文介绍了如何在数据不满一页时自动隐藏MJRefresh的底部加载更多提示。通过创建UITableView的分类,监听MJFooter的frame变化,判断其是否在屏幕显示区域内,从而更新footer文字并隐藏。提供了具体的代码实现和使用方法。

近期项目用到了mjrefresh,产品要求列表的数据不满一页的话就自动隐藏下面的“上拉加载更多”或是“到底了”,写了个UItableview的分类来实现了这个功能,主要原理就是:数据加载完成时如果tableview的footer也就是mj_footer在屏幕显示区域,则说明列表数据不满一页,将footer的文字@“”,从而达到隐藏的目的。

代码如下:

// MJRefresh+FooterManger.h

#import <UIKit/UIKit.h>

#import "MJRefresh.h"


typedef NS_ENUM(NSInteger, MJFooterRefreshState) {

    MJFooterRefreshStateNormal,

    MJFooterRefreshStateLoadMore,

    MJFooterRefreshStateNoMore

};


@interface UITableView (MJRefreshAutoManger)

@property (nonatomic,assign)MJFooterRefreshState footRefreshState;


@end


// MJRefresh+FooterManger.m

#import "MJRefresh+FooterManger.h"


@implementation UITableView (MJAutoRefreshFooterManger)


static char stateKey;

- (void)setFootRefreshState:(MJFooterRefreshState)footRefreshState {

    UIWindow *window = [UIApplicationsharedApplication].keyWindow;

    [RACObserve(self.mj_footer, frame)subscribeNext:^(id x) {  //这里的意思是监视mj_footer的frame变化,可以使用kvo代替RACObserve

        CGPoint point = [selfconvertPoint:self.mj_footer.frame.origintoView:window];

        if (point.y < window.frame.size.height) {

            [(MJRefreshAutoNormalFooter *)self.mj_footersetTitle:@""forState:MJRefreshStateNoMoreData];

            [self.mj_footerendRefreshingWithNoMoreData];

        }

    }];

    

    [selfhandleFooterRefresh:footRefreshState];

    NSString *value = [NSStringstringWithFormat:@"%ld", (long)footRefreshState];

    objc_setAssociatedObject(self, &stateKey, value, OBJC_ASSOCIATION_COPY_NONATOMIC);

}


- (MJFooterRefreshState)footRefreshState {

    NSString *refreshState =objc_getAssociatedObject(self, &stateKey);

    if ([refreshStateisEqualToString:@"MJFooterRefreshStateLoadMore"]) {

        returnMJFooterRefreshStateNoMore;

    }

    else {

        returnMJFooterRefreshStateLoadMore;

    }

}


- (void) handleFooterRefresh: (MJFooterRefreshState)footRefreshState {

    MJRefreshAutoNormalFooter *footer = (MJRefreshAutoNormalFooter*)self.mj_footer;

    switch (footRefreshState) {

        caseMJFooterRefreshStateNormal: {

            [footer setTitle:@""forState:MJRefreshStateIdle];

            break;

        }

        caseMJFooterRefreshStateLoadMore: {

            [self.mj_footerendRefreshing];

            break;

        }

        caseMJFooterRefreshStateNoMore: {

            [footer setTitle:NO_MORE_DATA_TEXTforState:MJRefreshStateNoMoreData];

            [self.mj_footerendRefreshingWithNoMoreData];

            break;

        }

        default:

            break;

    }

}


@end


使用方法:

1. 在tableView.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock之后初始化刷新状态:

eg:

_tableView.mj_footer = [MJRefreshAutoNormalFooterfooterWithRefreshingBlock:^{

  }];

 _tableView.footRefreshState =MJFooterRefreshStateNormal;


2、用_tableView.footRefreshState =MJFooterRefreshStateLoadMore;替代你代码的[_tableView.mj_footerendRefreshing];

_tableView.footRefreshState =MJFooterRefreshStateNoMore;替代你代码的[_tableView.mj_footerendRefreshingWithNoMoreData];


有问题一块讨论:qq:1246489125

mj_kinematics是一个在MuJoCo中用于计算全局笛卡尔位姿的函数。在MuJoCo里,mjData中的派生量需要显式传播,而mj_kinematics是最基本的所需函数,它能够计算所有对象(不包括相机和灯光)的全局笛卡尔位姿,可用于基本的渲染、模拟和动画等操作[^1]。 在代码实现中,mj_kinematics在mj_fwdPosition函数里被调用,此函数用于进行与位置相关的计算。以下是mj_fwdPosition函数的代码示例,其中包含了mj_kinematics的调用: ```c // position-dependent computations void mj_fwdPosition(const mjModel* m, mjData* d) { TM_START1; TM_START; mj_kinematics(m, d); mj_comPos(m, d); mj_camlight(m, d); mj_flex(m, d); mj_tendon(m, d); TM_END(mjTIMER_POS_KINEMATICS); // no threadpool: inertia and collision on main thread if (!d->threadpool) { mj_crb(m, d); // timed internally (POS_INERTIA) mj_factorM(m, d); // timed internally (POS_INERTIA) mj_collision(m, d); // timed internally (POS_COLLISION) } // have threadpool: inertia and collision on separate threads else { //... ... } TM_RESTART; mj_makeConstraint(m, d); if (mjENABLED(mjENBL_ISLAND)) { mj_island(m, d); } TM_END(mjTIMER_POS_MAKE); TM_RESTART; mj_transmission(m, d); TM_ADD(mjTIMER_POS_KINEMATICS); TM_RESTART; mj_projectConstraint(m, d); TM_END(mjTIMER_POS_PROJECT); TM_END1(mjTIMER_POSITION); } ``` 在调用一些函数(如mj_jacDot)前,需要先执行mj_kinematics、mj_comPos和mj_comVel来更新模型的状态,以确保计算的准确性[^3]。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值