Skip to content

Commit 55adebc

Browse files
committed
Merge pull request #5 from Remki/hideViewUnderTranslucentNavBar
Added property shouldHideUnderTranslucentNavigationBar in SVPullToRefres...
2 parents c790488 + 1c89af1 commit 55adebc

2 files changed

Lines changed: 30 additions & 1 deletion

File tree

SVPullToRefresh/UIScrollView+SVPullToRefresh.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ typedef NS_ENUM(NSUInteger, SVPullToRefreshState) {
4141

4242
@property (nonatomic, strong) UIColor *arrowColor;
4343
@property (nonatomic, strong) UIColor *textColor;
44+
@property (nonatomic, assign) BOOL shouldHideUnderTranslucentNavigationBar;
4445
@property (nonatomic, strong, readonly) UILabel *titleLabel;
4546
@property (nonatomic, strong, readonly) UILabel *subtitleLabel;
4647
@property (nonatomic, strong, readwrite) UIColor *activityIndicatorViewColor NS_AVAILABLE_IOS(5_0);

SVPullToRefresh/UIScrollView+SVPullToRefresh.m

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,12 @@ @implementation SVPullToRefreshView
171171
@synthesize titleLabel = _titleLabel;
172172
@synthesize dateLabel = _dateLabel;
173173

174+
- (void)setShouldHideUnderTranslucentNavigationBar:(BOOL)shouldHideUnderTranslucentNavigationBar {
175+
if (_shouldHideUnderTranslucentNavigationBar != shouldHideUnderTranslucentNavigationBar) {
176+
self.alpha = shouldHideUnderTranslucentNavigationBar ? 0.0f : 1.0f;
177+
_shouldHideUnderTranslucentNavigationBar = shouldHideUnderTranslucentNavigationBar;
178+
}
179+
}
174180

175181
- (id)initWithFrame:(CGRect)frame {
176182
if(self = [super initWithFrame:frame]) {
@@ -391,7 +397,7 @@ - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(N
391397
else if([keyPath isEqualToString:@"frame"]) {
392398
[self layoutSubviews];
393399
}
394-
else if ([keyPath isEqualToString:@"contentInset"]) {
400+
else if([keyPath isEqualToString:@"contentInset"]) {
395401
if (self.state != SVPullToRefreshStateLoading) {
396402
self.originalTopInset = self.scrollView.contentInset.top;
397403
self.originalBottomInset = self.scrollView.contentInset.bottom;
@@ -400,17 +406,39 @@ - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(N
400406

401407
}
402408

409+
- (void)adjustAlphaToVisiblePullToRefreshHeight:(CGFloat)pullToRefreshViewVisibleHeight {
410+
if(self.shouldHideUnderTranslucentNavigationBar) {
411+
static CGFloat alphaEquationVariableA = 0.0f;
412+
static CGFloat alphaEquationVariableB = 0.0f;
413+
414+
static dispatch_once_t onceToken;
415+
dispatch_once(&onceToken, ^{
416+
CGFloat startRaisingAlphaAtPoint = 5.0f;
417+
CGFloat reachMaximumAlphaAtPoint = 30.0f;
418+
419+
alphaEquationVariableA = 1.0f / (reachMaximumAlphaAtPoint - startRaisingAlphaAtPoint);
420+
alphaEquationVariableB = -1.0f * (startRaisingAlphaAtPoint / (reachMaximumAlphaAtPoint - startRaisingAlphaAtPoint));
421+
});
422+
423+
self.alpha = alphaEquationVariableA * pullToRefreshViewVisibleHeight + alphaEquationVariableB;
424+
}
425+
}
426+
403427
- (void)scrollViewDidScroll:(CGPoint)contentOffset {
404428
if(self.state != SVPullToRefreshStateLoading) {
405429
CGFloat scrollOffsetThreshold = 0;
430+
CGFloat pullToRefreshViewVisibleHeight = 0;
406431
switch (self.position) {
407432
case SVPullToRefreshPositionTop:
408433
scrollOffsetThreshold = self.frame.origin.y - self.originalTopInset;
434+
pullToRefreshViewVisibleHeight = scrollOffsetThreshold + self.bounds.size.height - contentOffset.y;
409435
break;
410436
case SVPullToRefreshPositionBottom:
411437
scrollOffsetThreshold = MAX(self.scrollView.contentSize.height - self.scrollView.bounds.size.height, 0.0f) + self.bounds.size.height + self.originalBottomInset;
438+
pullToRefreshViewVisibleHeight = contentOffset.y + self.bounds.size.height - scrollOffsetThreshold;
412439
break;
413440
}
441+
[self adjustAlphaToVisiblePullToRefreshHeight:pullToRefreshViewVisibleHeight];
414442

415443
if(!self.scrollView.isDragging && self.state == SVPullToRefreshStateTriggered)
416444
self.state = SVPullToRefreshStateLoading;

0 commit comments

Comments
 (0)