@@ -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