Skip to content

Commit

Permalink
fix inset bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
SolaWing committed Apr 1, 2016
1 parent 70795b7 commit 72d70a4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
12 changes: 7 additions & 5 deletions SWRefresh/SWRefreshAutoFooterViewModel.m
Original file line number Diff line number Diff line change
Expand Up @@ -24,30 +24,32 @@ - (void)setRefreshThreshold:(CGFloat)refreshThreshold {
}
}

static inline void scrollViewChangeBottomInset(UIScrollView* scrollView, CGFloat deltaBottomInset) {
static inline void scrollViewChangeBottomInset(SWRefreshViewModel* model, UIScrollView* scrollView, CGFloat deltaBottomInset) {
if (deltaBottomInset == 0) return;
UIEdgeInsets inset = scrollView.contentInset;
inset.bottom += deltaBottomInset;
scrollView.contentInset = inset;
// SWRefreshViewModel inner should always use setScrollViewTempInset, to avoid
// override scrollViewOriginInsets when already set a tempinset like top
[model setScrollViewTempInset:inset];
}

- (void)setBottomInset:(CGFloat)bottomInset {
if (bottomInset != _bottomInset) {
if (self.scrollView) {
scrollViewChangeBottomInset(self.scrollView, bottomInset - _bottomInset);
scrollViewChangeBottomInset(self, self.scrollView, bottomInset - _bottomInset);
}
_bottomInset = bottomInset;
}
}

- (void)bindScrollView:(UIScrollView *)scrollView {
[super bindScrollView:scrollView];
scrollViewChangeBottomInset(scrollView, _bottomInset);
scrollViewChangeBottomInset(self, scrollView, _bottomInset);
}

- (void)unbindScrollView:(UIScrollView *)scrollView {
[super unbindScrollView:scrollView];
scrollViewChangeBottomInset(scrollView, -_bottomInset);
scrollViewChangeBottomInset(self, scrollView, -_bottomInset);
}

- (void)scrollViewContentOffsetDidChange:(NSDictionary *)change {
Expand Down
13 changes: 9 additions & 4 deletions SWRefresh/SWRefreshViewModel.m
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,15 @@ - (void)setState:(SWRefreshState)state {
- (void)setScrollViewTempInset:(UIEdgeInsets)inset {
UIScrollView* scrollView = self.scrollView;
if (scrollView) {
id value = @YES;
objc_setAssociatedObject(scrollView, &TempInsetKey, value, OBJC_ASSOCIATION_ASSIGN);
scrollView.contentInset = inset;
objc_setAssociatedObject(scrollView, &TempInsetKey, nil, OBJC_ASSOCIATION_ASSIGN);
if ([self isSettingTempInset]) {
// sometimes KVO change inset
scrollView.contentInset = inset;
} else {
id value = @YES;
objc_setAssociatedObject(scrollView, &TempInsetKey, value, OBJC_ASSOCIATION_ASSIGN);
scrollView.contentInset = inset;
objc_setAssociatedObject(scrollView, &TempInsetKey, nil, OBJC_ASSOCIATION_ASSIGN);
}
}
}

Expand Down

0 comments on commit 72d70a4

Please sign in to comment.