Comments (5)
// 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.
1.在第一次加载时headview 会 向上偏item的高度
2.tableview 在cell少是会自适应contentsize 导致headView 回弹 你是在
- (void)adjustItemViewContentSize:(UIScrollView *)itemView atIndex:(NSInteger)index
方法中解决的吗 ??
from swipetableview.
不是清楚你的问题。你能否提供截屏附件等信息
from swipetableview.
from swipetableview.
867599670
from swipetableview.
Related Issues (20)
- 给继承自STCollectionView 的collectionview 添加MJRefreshHeader 下拉刷新回弹位置错误 HOT 1
- 使用方法还是太不方便了
- alwaysBounceHorizontal 属性没有效果
- 添加mj_header位置问题 HOT 1
- reoloadData无效
- swipeTableViewWillBeginDragging不响应
- Tableview的点击
- Multiple methods named 'frame' found with mismatched result, parameter type or attributes HOT 2
- MJRefresh上拉加载更多 偏移量问题 HOT 2
- 动态修改headview高度的时候显示不正确
- 没有用autolayout的后果
- iOS12 - iPhoneXS 右滑crash HOT 3
- 从别的页面返回更新headerView的高度时布局不对 HOT 1
- 提两点功能补充
- iPhone X适配 和 sectionHeader问题
- iOS 8 crash
- STHeaderView 手势冲突问题
- 如果进入页面,想指定某一个item展示,而不是默认第一个item0,怎么处理?是不是应该暴露一个selectedIndex HOT 1
- attempt to scroll to invalid index path:
- 在维护App的时候,发现了前人集成了这个东西,代码耦合度高的吓人,还很容易触发异步刷新的crash问题,虽然我做了很多修改,源码也做了修改。controller 代码就有5000行,我是心力交瘁啊 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from swipetableview.