1111@interface STSpringScrollView ()
1212@property (nonatomic , assign ) float refreshHeaderHeight;
1313@property (nonatomic , assign ) float loadingFooterHeight;
14- @property (nonatomic , assign ) UIEdgeInsets orgInsets;
14+ // @property(nonatomic, assign) UIEdgeInsets orgInsets;
1515@property (nonatomic , copy ) NSString *refreshStatus;
1616@property (nonatomic , copy ) NSString *loadingStatus;
17- @property (nonatomic , assign ) BOOL orgScrollEnabled;
1817@property (nonatomic , copy ) NSDictionary *initialContentOffset;
1918@property (nonatomic , assign ) BOOL allLoaded;
2019@property (nonatomic , assign ) BOOL initialed;
@@ -53,16 +52,17 @@ - (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL
5352 [super scrollViewDidEndDragging: scrollView willDecelerate: decelerate];
5453 if ([self shouldRefresh ]) {
5554 self.refreshStatus = @" refreshing" ;
56- self.orgInsets = self.scrollView .contentInset ;
57- [self .scrollView setContentInset: UIEdgeInsetsMake (self .orgInsets.top+self .refreshHeaderHeight, self .orgInsets.left, self .orgInsets.bottom, self .orgInsets.right)];
55+ [self .scrollView setContentInset: UIEdgeInsetsMake (self .refreshHeaderHeight, 0 , 0 , 0 )];
5856 } else if ([self shouldLoad ]) {
5957 self.loadingStatus = @" loading" ;
60- self.orgInsets = self.scrollView .contentInset ;
6158 CGFloat fill = .0f ;
6259 if (self.scrollView .frame .size .height >self.scrollView .contentSize .height ){
6360 fill=self.scrollView .frame .size .height -self.scrollView .contentSize .height ;
6461 }
65- [self .scrollView setContentInset: UIEdgeInsetsMake (self .orgInsets.top, self .orgInsets.left, self .orgInsets.bottom+self .loadingFooterHeight+fill, self .orgInsets.right)];
62+ [self .scrollView setContentInset: UIEdgeInsetsMake (0 , 0 , self .loadingFooterHeight+fill, 0 )];
63+ }
64+ else if ([self hitRefreshStatus: @[@" rebound" ]] && !UIEdgeInsetsEqualToEdgeInsets (UIEdgeInsetsZero, scrollView.contentInset )){
65+ [self .scrollView setContentOffset: CGPointMake (0 , 0 ) animated: YES ];
6666 }
6767}
6868
@@ -75,6 +75,7 @@ - (void)scrollViewDidScroll:(UIScrollView *)scrollView {
7575 self.refreshStatus = @" pullingCancel" ;
7676 } else if ([self shouldWaiting ]){
7777 self.refreshStatus = @" waiting" ;
78+ scrollView.contentInset = UIEdgeInsetsZero;
7879 }
7980 if ([self shouldDragging ]) {
8081 self.loadingStatus = @" dragging" ;
@@ -84,21 +85,15 @@ - (void)scrollViewDidScroll:(UIScrollView *)scrollView {
8485 self.loadingStatus = @" draggingCancel" ;
8586 } else if ([self shouldFooterWaiting ]) {
8687 self.loadingStatus = @" waiting" ;
88+ scrollView.contentInset = UIEdgeInsetsZero;
8789 }
8890 [super scrollViewDidScroll: scrollView];
8991}
9092
91- - (void )scrollViewDidEndScrollingAnimation : (UIScrollView *)scrollView {
92- if (!UIEdgeInsetsEqualToEdgeInsets (scrollView.contentInset , self.orgInsets ) && ([self hitRefreshStatus: @[@" waiting" ]] || [self hitLoadingStatus: @[@" waiting" ]])) {
93- scrollView.contentInset = self.orgInsets ;
94- }
95- }
96-
9793- (void )endRefresh {
9894 if ([self hitRefreshStatus: @[@" refreshing" ]]) {
9995 self.refreshStatus = @" rebound" ;
100- [self .scrollView setContentOffset: CGPointMake (0 , 0 ) animated: YES ];
101- self.orgScrollEnabled = self.scrollView .scrollEnabled ;
96+ [self .scrollView setContentOffset: CGPointMake (self .scrollView.contentOffset.x, 0 ) animated: YES ];
10297 }
10398}
10499
@@ -126,7 +121,7 @@ - (BOOL) shouldPullingCancel{
126121}
127122
128123- (BOOL ) shouldWaiting {
129- return self.refreshHeaderHeight >0 && ([self hitRefreshStatus: @[@" rebound" ,@" pullingCancel" ]]) && self.scrollView .contentOffset .y >=0 ;
124+ return self.refreshHeaderHeight >0 && ([self hitRefreshStatus: @[@" rebound" ,@" pullingCancel" ]]) && ! UIEdgeInsetsEqualToEdgeInsets (UIEdgeInsetsZero, self. scrollView . contentInset ) && self.scrollView .contentOffset .y >=0 ;
130125}
131126
132127- (BOOL ) shouldDragging {
@@ -207,8 +202,8 @@ - (void)scrollToOffset:(CGPoint)offset animated:(BOOL)animated{
207202
208203- (void )setAllLoaded : (BOOL )allLoaded {
209204 self.loadingStatus = allLoaded?@" allLoaded" :@" waiting" ;
210- if (allLoaded && !UIEdgeInsetsEqualToEdgeInsets (self. orgInsets , self.scrollView .contentInset )) {
211- [self .scrollView setContentInset: self .orgInsets ];
205+ if (allLoaded && !UIEdgeInsetsEqualToEdgeInsets (UIEdgeInsetsZero , self.scrollView .contentInset )) {
206+ [self .scrollView setContentInset: UIEdgeInsetsZero ];
212207 }
213208 [self sendScrollEventWithName: @" onScroll" scrollView: self .scrollView userData: @{}];
214209}
0 commit comments