自定义HMSegmentedPager以隐藏分段控件

时间:2018-06-29 03:28:35

标签: ios

我正在使用HMSegmetedPager,它工作正常,但现在我想当我向上滚动时,分段控件将隐藏而不是固定在顶部,而当我向下滚动时,它将立即显示。 我试图弄清楚但仍然卡住了:( 我想我需要在MXScrollView.m文件的以下功能中修复或添加更多代码:

- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context {

if (context == kMXScrollViewKVOContext && [keyPath isEqualToString:NSStringFromSelector(@selector(contentOffset))]) {

    CGPoint new = [[change objectForKey:NSKeyValueChangeNewKey] CGPointValue];
    CGPoint old = [[change objectForKey:NSKeyValueChangeOldKey] CGPointValue];
    CGFloat diff = old.y - new.y;

    if (diff == 0.0 || !_isObserving) return;

    if (object == self) {
        //Adjust self scroll offset when scroll down
        if (diff > 0 && _lock) {
            [self scrollView:self setContentOffset:old];
        } else if (self.contentOffset.y < -self.contentInset.top && !self.bounces) {
            [self scrollView:self setContentOffset:CGPointMake(self.contentOffset.x, -self.contentInset.top)];
        } else if (self.contentOffset.y > -self.parallaxHeader.minimumHeight) {
            [self scrollView:self setContentOffset:CGPointMake(self.contentOffset.x, -self.parallaxHeader.minimumHeight)];
        }
    } else {
        //Adjust the observed scrollview's content offset
        UIScrollView *scrollView = object;
        _lock = (scrollView.contentOffset.y > -scrollView.contentInset.top);

        //Manage scroll up
        if (self.contentOffset.y < -self.parallaxHeader.minimumHeight && _lock && diff < 0) {
            [self scrollView:scrollView setContentOffset:old];
        }
        //Disable bouncing when scroll down
        if (!_lock && ((self.contentOffset.y > -self.contentInset.top) || self.bounces)) {
            [self scrollView:scrollView setContentOffset:CGPointMake(scrollView.contentOffset.x, -scrollView.contentInset.top)];
        }
    }
} else {
    [super observeValueForKeyPath:keyPath ofObject:object change:change context:context];
}
}

感谢任何建议!

0 个答案:

没有答案