当前位置:网站首页>Scrollview, tableview nested solutions
Scrollview, tableview nested solutions
2022-07-28 00:58:00 【Blue feather screen】
scrollview、tableView Nested solutions
I found a lot on the Internet , There is no favorite scheme . It also refers to many designs , I made one that I think is relatively simple 、 The perfect solution :
General train of thought : Outer layer placement scrollview As a container , The upper part of the container topView, Lower part tableView. When tableView Rolling time , If topView Still in the exhibition area , Is set topView Of y coordinate , Give Way topView Move up with synchronization .
( Be careful : If not set tableView Of headerView,tableView、 and topView It will move up at the same time, which is not the effect I want , So set tableView Of headerView Height includes topView Height , Achieved a perfect effect , In terms of specific implementation demo)
Results the preview :

The core code is in the parent view 、 Rolling judgment of sub attempt
// Callback of parent view scrolling , Used for horizontal scroll judgment
// Callback of parent view scrolling , Used for horizontal scroll judgment
- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
CGFloat placeholderOffset = 0;
if (self.topView.selectedIndex == 0) {
if (self.firstTableView.contentOffset.y > CGRectGetHeight(self.topView.frame) - kItemheight) {
placeholderOffset = CGRectGetHeight(self.topView.frame) - kItemheight;
}else {
placeholderOffset = self.firstTableView.contentOffset.y;
}
[self.secondTableView setContentOffset:CGPointMake(0, placeholderOffset) animated:NO];
}else {
if (self.secondTableView.contentOffset.y > CGRectGetHeight(self.topView.frame) - kItemheight) {
placeholderOffset = CGRectGetHeight(self.topView.frame) - kItemheight;
}else {
placeholderOffset = self.secondTableView.contentOffset.y;
}
[self.firstTableView setContentOffset:CGPointMake(0, placeholderOffset) animated:NO];
}
}
// Callback of subview scrolling , Used for rolling judgment in the vertical direction
// Callback of subview scrolling , Used for rolling judgment in the vertical direction
- (void)updateTopViewFrame:(UIScrollView *)scrollView{
CGFloat placeHolderHeight = CGRectGetHeight(self.topView.frame) - self.topView.itemHeight;
CGFloat offsetY = scrollView.contentOffset.y;
CGFloat y = 0.0;
if (offsetY >= 0 && (offsetY <= placeHolderHeight)) {
y = -offsetY;
} else if (offsetY > placeHolderHeight) {
y = -placeHolderHeight;
} else if (offsetY < 0) {
y = -offsetY;
}
[self.topView mas_updateConstraints:^(MASConstraintMaker *make) {
make.top.offset(y + kNavBarHeight);
}];
}
githut demo Download address :https://github.com/biyuhuaping/NestScrollView
边栏推荐
- IP address & subnet mask
- ASML推出第一代HMI多光束检测机:速度提升600%,适用于5nm及更先进工艺
- startUMl
- Impact of privilege changes on existing connections
- [meetup preview] openmldb + ONEFLOW: link feature engineering to model training to accelerate machine learning model development
- Jerry, if you turn on Bluetooth again, one for two. When the mobile phone is connected to the prototype, it will appear and cannot be connected [chapter]
- 特权更改对现有连接的影响
- Function related knowledge
- Jerry caused other messages to accumulate in the message pool [article]
- Current situation of semiconductor testing equipment Market: the localization rate is still less than 10%!
猜你喜欢
随机推荐
【OpenCV 例程 300篇】241. 尺度不变特征变换(SIFT)
Firefox 103, the Firefox browser, has been released to improve performance under high refresh rate displays
深度刨析数据在内存中的存储
Point divide and conquer analysis
【原】【爬虫系列】简要获取一下知乎的最热门话题相关主题及描述信息
Swear, swear, swear
半导体测试设备市场现状:国产化率仍不足10%!
Basic operations of MySQL database (2) --- Based on data table
Buildforge materials
Network equipment hard core technology insider firewall and security gateway chapter (VI) security double repair under the law
自动推理的逻辑09–自动定理证明
估值360亿美元!即将进行首次载人发射的SpaceX筹资3.46亿美元
加拿大法院认定孟晚舟“双重犯罪”成立,引渡程序将继续进行!
MySQL limit usage and large paging problem solving
Threejs personal notes
函数相关知识
The program design questions of the 11th national competition of Bluebridge cup single chip microcomputer
Selection of FFT sampling frequency and sampling points
LeetCode - 寻找两个正序数组的中位数
Data analysis: disassembly method (details)



![Jerry Zhi doesn't play hidden audio files [article]](/img/09/b9fb293151f56d2a93f8a1c8f3d0dc.png)




