123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- //
- // UICollectionView+MJRefreshAutoManger.m
- // YouHuiProject
- //
- // Created by 小花 on 2018/5/17.
- // Copyright © 2018年 kuxuan. All rights reserved.
- //
- #import "UICollectionView+MJRefreshAutoManger.h"
- #define NO_MORE_DATA_TEXT @"无更多数据了"
- @implementation UICollectionView (MJRefreshAutoManger)
- static char stateKey;
- - (void)setFootRefreshState:(MJFooterRefreshState)footRefreshState {
-
- UIWindow *window = [UIApplication sharedApplication].keyWindow;
- [RACObserve(self.mj_footer, frame)subscribeNext:^(id x) { //这里的意思是监视mj_footer的frame变化,可以使用kvo代替RACObserve
- CGPoint point = [self convertPoint:self.mj_footer.frame.origin toView:window];
-
- if (point.y < window.frame.size.height) {
-
- [(MJRefreshAutoNormalFooter *)self.mj_footer setTitle:@"" forState:MJRefreshStateIdle];
-
- }else {
- [(MJRefreshAutoNormalFooter *)self.mj_footer setTitle:@"点击或上拉加载更多" forState:MJRefreshStateIdle];
- [(MJRefreshAutoNormalFooter *)self.mj_footer resetNoMoreData];
- }
-
- }];
- [self handleFooterRefresh:footRefreshState];
-
- NSString *value = [NSString stringWithFormat:@"%ld", (long)footRefreshState];
- objc_setAssociatedObject(self, &stateKey, value, OBJC_ASSOCIATION_COPY_NONATOMIC);
-
- }
- - (MJFooterRefreshState)footRefreshState {
-
- NSString *refreshState = objc_getAssociatedObject(self, &stateKey);
- if ([refreshState isEqualToString:@"MJFooterRefreshStateLoadMore"]) {
- return MJFooterRefreshStateNoMore;
- }
- else {
- return MJFooterRefreshStateLoadMore;
- }
-
- }
- - (void)handleFooterRefresh: (MJFooterRefreshState)footRefreshState {
-
- MJRefreshAutoNormalFooter *footer = (MJRefreshAutoNormalFooter*)self.mj_footer;
- switch (footRefreshState) {
- case MJFooterRefreshStateNormal:
- {
- [footer setTitle:@"" forState:MJRefreshStateIdle];
- break;
- }
-
- case MJFooterRefreshStateLoadMore:
- {
- [self.mj_footer endRefreshing];
- break;
- }
-
- case MJFooterRefreshStateNoMore:
- {
- [footer setTitle:NO_MORE_DATA_TEXT forState:MJRefreshStateNoMoreData];
- [self.mj_footer endRefreshingWithNoMoreData];
- break;
-
- }
- default:
-
- break;
-
- }
-
- }
- @end
|