Skip to content
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

Update contentInset properly, set a specific size for the pull to refresh view #226

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions SVPullToRefresh/UIScrollView+SVPullToRefresh.m
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#define fequal(a,b) (fabs((a) - (b)) < FLT_EPSILON)
#define fequalzero(a) (fabs(a) < FLT_EPSILON)

static CGFloat const SVPullToRefreshViewHeight = 60;
static CGFloat const SVPullToRefreshViewHeight = 90;

@interface SVPullToRefreshArrow : UIView

Expand Down Expand Up @@ -119,6 +119,7 @@ - (void)setShowsPullToRefresh:(BOOL)showsPullToRefresh {

if(!showsPullToRefresh) {
if (self.pullToRefreshView.isObserving) {
[self removeObserver:self.pullToRefreshView forKeyPath:@"contentInset"];
[self removeObserver:self.pullToRefreshView forKeyPath:@"contentOffset"];
[self removeObserver:self.pullToRefreshView forKeyPath:@"contentSize"];
[self removeObserver:self.pullToRefreshView forKeyPath:@"frame"];
Expand All @@ -128,6 +129,7 @@ - (void)setShowsPullToRefresh:(BOOL)showsPullToRefresh {
}
else {
if (!self.pullToRefreshView.isObserving) {
[self addObserver:self.pullToRefreshView forKeyPath:@"contentInset" options:NSKeyValueObservingOptionNew context:nil];
[self addObserver:self.pullToRefreshView forKeyPath:@"contentOffset" options:NSKeyValueObservingOptionNew context:nil];
[self addObserver:self.pullToRefreshView forKeyPath:@"contentSize" options:NSKeyValueObservingOptionNew context:nil];
[self addObserver:self.pullToRefreshView forKeyPath:@"frame" options:NSKeyValueObservingOptionNew context:nil];
Expand Down Expand Up @@ -200,6 +202,7 @@ - (void)willMoveToSuperview:(UIView *)newSuperview {
if (scrollView.showsPullToRefresh) {
if (self.isObserving) {
//If enter this branch, it is the moment just before "SVPullToRefreshView's dealloc", so remove observer here
[scrollView removeObserver:self forKeyPath:@"contentInset"];
[scrollView removeObserver:self forKeyPath:@"contentOffset"];
[scrollView removeObserver:self forKeyPath:@"contentSize"];
[scrollView removeObserver:self forKeyPath:@"frame"];
Expand Down Expand Up @@ -385,8 +388,15 @@ - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(N
}
self.frame = CGRectMake(0, yOrigin, self.bounds.size.width, SVPullToRefreshViewHeight);
}
else if([keyPath isEqualToString:@"frame"])
else if([keyPath isEqualToString:@"frame"]) {
[self layoutSubviews];
}
else if ([keyPath isEqualToString:@"contentInset"]) {
if (self.state != SVPullToRefreshStateLoading) {
self.originalTopInset = self.scrollView.contentInset.top;
self.originalBottomInset = self.scrollView.contentInset.bottom;
}
}

}

Expand Down