Giter Site home page Giter Site logo

你好 ,有个问题 能否加个属性 使headView 既可以固定在顶部 又可以随tableview 上下滑动 about swipetableview HOT 5 OPEN

liangdrime avatar liangdrime commented on May 21, 2024
你好 ,有个问题 能否加个属性 使headView 既可以固定在顶部 又可以随tableview 上下滑动

from swipetableview.

Comments (5)

liangdrime avatar liangdrime commented on May 21, 2024
//  SwipeTableView.h

@property (nonatomic, assign) BOOL swipeHeaderViewScrollDisabled;



//  SwipeTableView.m

@property (nonatomic, assign) BOOL scrollItemUp;  // 当前item滚动的方向
@property (nonatomic, assign) BOOL willStopHeaderFlag;  // 在设置header可以悬停的时候,作为header在将来可以悬停的标记

....
- (void)setSwipeHeaderViewScrollDisabled:(BOOL)swipeHeaderViewScrollDisabled {
    _swipeHeaderViewScrollDisabled = swipeHeaderViewScrollDisabled;
    // 重置 KVO contentOffset 对header的改变
    _contentOffsetKVODisabled = NO;
}

....

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

    /** contentOffset */
    if (context == SwipeTableViewItemContentOffsetContext) {

        if (_contentOffsetKVODisabled) {
            return;
        }
        CGFloat oldOffsetY      = [change[NSKeyValueChangeOldKey] CGPointValue].y;
        CGFloat newOffsetY      = [change[NSKeyValueChangeNewKey] CGPointValue].y;

        .....

        BOOL scrollDirection = newOffsetY - oldOffsetY > 0;
        // 方向改变时,重置header的预处理标记为NO
        if (_scrollItemUp != scrollDirection) {
            _willStopHeaderFlag = NO;
        }
        _scrollItemUp = scrollDirection;

        if (_swipeHeaderViewScrollDisabled) {
            // 可以添加一个属性动态改变这个值,作为header悬停的目标位置
            CGFloat defaultHeadrTop = _swipeHeaderTopInset;

            if (_scrollItemUp) {
                NSLog(@"向上........");
                // 向上滚动并且header在目标位置以下,标记header在将来可以悬停
                if (_swipeHeaderView.st_top > defaultHeadrTop) {
                    _willStopHeaderFlag = YES;
                }
                // header滚动向上滚动超过目标位置,如果header的标记是可以悬停,则悬停header,并取消contentOffset对header的改变操作
                else {
                    if (_willStopHeaderFlag) {
                        _swipeHeaderView.st_top = defaultHeadrTop;
                        _swipeHeaderBar.st_top = _swipeHeaderView.st_bottom;
                        _contentOffsetKVODisabled = YES;
                        _willStopHeaderFlag = NO;
                    }
                }
            }else {
                NSLog(@"向下........");
                // 向下滚动并且header在目标位置以上,标记header在将来可以悬停
                if (_swipeHeaderView.st_top < defaultHeadrTop) {
                    _willStopHeaderFlag = YES;
                }
                // header滚动向下滚动超过目标位置,如果header的标记是可以悬停,则悬停header,并取消contentOffset对header的改变操作
                else {
                    if (_willStopHeaderFlag) {
                        _swipeHeaderView.st_top = defaultHeadrTop;
                        _swipeHeaderBar.st_top = _swipeHeaderView.st_bottom;
                        _contentOffsetKVODisabled = YES;
                        _willStopHeaderFlag = NO;
                    }
                }
            }
        }
    }
}

这是简单的实现思路原理,你参考一下。具体的需求可以自己作调整。测试这段代码可以滚动item到魔偶个位置,然后设置_swipeHeaderViewScrollDisabled = NO,再次滚动的时候,到指定位置后header便可以悬停了。

from swipetableview.

guang-sun avatar guang-sun commented on May 21, 2024

1.在第一次加载时headview 会 向上偏item的高度

2.tableview 在cell少是会自适应contentsize 导致headView 回弹 你是在

  • (void)adjustItemViewContentSize:(UIScrollView *)itemView atIndex:(NSInteger)index
    方法中解决的吗 ??

from swipetableview.

liangdrime avatar liangdrime commented on May 21, 2024

不是清楚你的问题。你能否提供截屏附件等信息

from swipetableview.

guang-sun avatar guang-sun commented on May 21, 2024

8c6bfeda-2fcd-4209-9918-8385c52cc65c
方便加一下你的qq吗

from swipetableview.

liangdrime avatar liangdrime commented on May 21, 2024

867599670

from swipetableview.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.