杨锴
2025-04-16 09a372bc45fde16fd42257ab6f78b8deeecf720b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
//
//  UIScrollView+FFPage.m
//  FFPage
//
//  Created by North on 2019/8/9.
//  Copyright © 2019 North. All rights reserved.
//
 
#import "UIScrollView+FFPage.h"
#import <objc/runtime.h>
#import "FFPage.h"
 
static void *TouchKey = @"touchKey";
static void *BlockKey = @"blockKey";
static void *FFHeaderRefreshKey = @"FFHeaderRefreshKey";
static void *FFFooterRefreshKey = @"FFFooterRefreshKey";
static void *AnimationKey = @"AnimationKey";
 
@implementation UIScrollView (FFPage)
 
- (void)setIsTouch:(BOOL)isTouch{
    
    if(isTouch != self.isTouch){
        
        objc_setAssociatedObject(self, TouchKey, @(isTouch).stringValue, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
        
        if([self blockArray]){
            
            for (TouchBlock block in [self blockArray]) {
                if(block) block(isTouch);
            }
            
        }
    }
}
 
- (BOOL)isTouch{
    
    return [objc_getAssociatedObject(self, TouchKey) boolValue];
    
}
 
- (void)addTounchBlock:(TouchBlock)block{
    
    NSMutableArray * array = [self blockArray] ? [self blockArray].mutableCopy : @[].mutableCopy;
    
    [array addObject:block];
    
    objc_setAssociatedObject(self, BlockKey, array, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}
 
 
- (NSMutableArray *)blockArray{
    
    return objc_getAssociatedObject(self, BlockKey);
}
 
 
 
- (BOOL)isReachTop{
    
    return self.contentOffset.y <= -self.contentInset.top;
}
 
- (BOOL)isReachLeft{
    
    return self.contentOffset.x <= -self.contentInset.left;
}
 
- (BOOL)isReachBottom{
    
    return self.contentOffset.y >= self.maxOffsetY;
}
 
- (BOOL)isReachRight{
    
    return self.contentOffset.x >= self.maxOffsetX;
}
- (CGFloat)maxOffsetX{
    
    return fmax(0, self.contentSize.width - CGRectGetWidth(self.bounds)) + self.contentInset.right;
}
 
- (CGFloat)maxOffsetY{
    
    return fmax(0, self.contentSize.height - CGRectGetHeight(self.bounds)) + self.contentInset.bottom;
}
 
- (void)setFf_header:(FFRereshView *)ff_header{
    
    if(ff_header != self.ff_header){
        [self.ff_header removeFromSuperview];
        [self insertSubview:ff_header atIndex:0];
        objc_setAssociatedObject(self, FFHeaderRefreshKey, ff_header, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
    }
    
}
- (FFRereshView *)ff_header{
    
    return objc_getAssociatedObject(self, FFHeaderRefreshKey);
}
 
 
- (void)setFf_footer:(FFRereshView *)ff_footer {
    
    if(ff_footer != self.ff_footer){
        [self.ff_footer removeFromSuperview];
        ff_footer.isFooter = YES;
        [self insertSubview:ff_footer atIndex:0];
        objc_setAssociatedObject(self, FFFooterRefreshKey, ff_footer, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
    }
}
 
 
- (FFRereshView *)ff_footer{
    
    return objc_getAssociatedObject(self, FFFooterRefreshKey);
}
 
 
 
- (void)setIsAnimationing:(BOOL)isAnimationing{
    
    objc_setAssociatedObject(self, AnimationKey, @(isAnimationing).stringValue, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}
 
- (BOOL)isAnimationing{
    
     return [objc_getAssociatedObject(self, AnimationKey) boolValue];
}
 
 
@end