-
Notifications
You must be signed in to change notification settings - Fork 10
bugfix: fix originalContentInsetBottom not update bug #12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -42,14 +42,18 @@ - (instancetype)initWithScrollView:(UIScrollView *)scrollView | |
| _autoLoadMore = YES; | ||
| _originalContentInsetBottom = scrollView.contentInset.bottom; | ||
|
|
||
| [self.scrollView addObserver:self | ||
| forKeyPath:@"contentOffset" | ||
| options:NSKeyValueObservingOptionNew | ||
| context:NULL]; | ||
| [_scrollView addObserver:self | ||
| forKeyPath:@"contentOffset" | ||
| options:NSKeyValueObservingOptionNew | ||
| context:NULL]; | ||
| [_scrollView addObserver:self | ||
| forKeyPath:@"contentSize" | ||
| options:NSKeyValueObservingOptionNew | ||
| context:NULL]; | ||
| [_scrollView addObserver:self | ||
| forKeyPath:@"contentInset" | ||
| options:NSKeyValueObservingOptionNew | ||
| context:NULL]; | ||
|
|
||
| [self setCustomView:[self defalutRefreshView]]; | ||
| [self setEnable:YES withAnimation:NO]; | ||
|
|
@@ -61,6 +65,7 @@ - (void)dealloc | |
| { | ||
| [self.scrollView removeObserver:self forKeyPath:@"contentOffset"]; | ||
| [self.scrollView removeObserver:self forKeyPath:@"contentSize"]; | ||
| [self.scrollView removeObserver:self forKeyPath:@"contentInset"]; | ||
| } | ||
|
|
||
| #pragma mark- Property | ||
|
|
@@ -210,9 +215,27 @@ - (void)observeValueForKeyPath:(NSString *)keyPath | |
| { | ||
| if ([keyPath isEqualToString:@"contentOffset"]) { | ||
| [self checkOffsetsWithChange:change]; | ||
| } else if ([keyPath isEqualToString:@"contentSize"]) { | ||
| } | ||
| else if ([keyPath isEqualToString:@"contentSize"]) { | ||
| [self layoutLoadMoreView]; | ||
| } | ||
| else if ([keyPath isEqualToString:@"contentInset"]) { // self.scrollView 的 contentInset变化后,需要更新 self.originalContentInsetBottom | ||
| CGFloat scrollViewInsetBottom = self.scrollView.contentInset.bottom; | ||
| CGFloat loadMoreViewHeight = self.loadMoreView.bounds.size.height; | ||
|
|
||
| // self.scrollView.contentInset.bottom 只可能存在下面两种情况; | ||
| // 如果不满足,说明系统更新了scrollView.contentInset,这时候需要更新 self.originalContentInsetBottom | ||
| if (scrollViewInsetBottom != self.originalContentInsetBottom | ||
| && scrollViewInsetBottom != self.originalContentInsetBottom + loadMoreViewHeight) { | ||
|
|
||
| if (scrollViewInsetBottom > self.originalContentInsetBottom + loadMoreViewHeight) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 这里应该是
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 其实这样最好,加上了状态的判断。
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 如果要支持可设置 contentinset |
||
| self.originalContentInsetBottom = scrollViewInsetBottom - self.originalContentInsetBottom -loadMoreViewHeight; | ||
| } | ||
| else if (scrollViewInsetBottom > self.originalContentInsetBottom) { | ||
| self.originalContentInsetBottom = scrollViewInsetBottom; | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| #pragma mark - Private Methods | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
需要调用一下
[self layoutLoadMoreView]?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
看起来不需要主动调用,layoutLoadMoreView 被调用的时候,这里的事情已经做过了。