96SEO 2026-02-23 12:17 25
UITableView是自带吸顶效果#xff0c;我们把需要置顶的控件设置为SectionHeaderView#xff0c;这样在滚动时#xff0c;该控件会…项目中在列表向上滚动时有时需要将某个控件置顶这就是我们常见的吸顶效果。

UITableView是自带吸顶效果我们把需要置顶的控件设置为SectionHeaderView这样在滚动时该控件会自动置顶。
NO;_tableView.showsVerticalScrollIndicator
forCellReuseIdentifier:CellId];}return
(NSInteger)numberOfSectionsInTableView:(UITableView
(NSInteger)tableView:(UITableView
numberOfRowsInSection:(NSInteger)section
(CGFloat)tableView:(UITableView
heightForRowAtIndexPath:(NSIndexPath
viewForHeaderInSection:(NSInteger)section
50)];headerView.backgroundColor
(CGFloat)tableView:(UITableView
heightForHeaderInSection:(NSInteger)section
cellForRowAtIndexPath:(NSIndexPath
dequeueReusableCellWithIdentifier:CellId
yellowColor];cell.textLabel.text
whiteColor];}cell.textLabel.text
style:UITableViewStylePlain];if
whiteColor];self.separatorColor
clearColor];self.separatorStyle
UITableViewCellSeparatorStyleNone;if
{self.contentInsetAdjustmentBehavior
UIScrollViewContentInsetAdjustmentNever;}self.estimatedRowHeight
0.000;self.estimatedSectionHeaderHeight
0.000;self.estimatedSectionFooterHeight
{self.automaticallyAdjustsScrollIndicatorInsets
去除表格头留白self.sectionHeaderTopPadding
UITableView的吸顶效果能满足部分的要求但在实际应用中需要置顶的往往是一些标签页对应的也是多个列表。
blueColor]];UKCustomTabItemView
addItemView:tabItemView1];UKCustomTabItemView
addItemView:tabItemView2];_tabView.delegate
viewForHeaderInSection:(NSInteger)section
cellForRowAtIndexPath:(NSIndexPath
dequeueReusableCellWithIdentifier:CellId
yellowColor];cell.textLabel.text
whiteColor];}cell.textLabel.text
(void)onTabViewSelected:(UKTabView
上述的方法简单地实现了标签页置顶和选项卡切换功能但由于我们只能共用一个列表所以会发生两个标签页都滚动的现象。
为此我们需要优化滚动的偏移首先在滚动结束时记录偏移量然后在切换标签页时设置原有的偏移量。
(void)scrollViewDidEndDragging:(UIScrollView
willDecelerate:(BOOL)decelerate
{NSLog(scrollViewDidEndDragging);[self
(void)scrollViewDidEndDecelerating:(UIScrollView
{NSLog(scrollViewDidEndDecelerating);[self
(void)recordOffset:(UIScrollView
scrollView.contentOffset.y;NSLog(tab1Offset
scrollView.contentOffset.y;NSLog(tab2Offset
(void)onTabViewSelected:(UKTabView
有时设置tableView.contentOffset无效需要提前刷新[self.tableView
虽然我们记录了原有的偏移量但从实际的效果来看切换时TabView会在同样的位置闪烁比较严重。
为此我们需要尽量保持TabView的位置。
(void)onTabViewSelected:(UKTabView
originOffset:self.tab2Offset];self.tableView.contentOffset
originOffset:self.tab1Offset];self.tableView.contentOffset
(CGFloat)getDestOffset:(CGFloat)destOffset
originOffset:(CGFloat)originOffset
内容只能用UIScrollView显示为了保持UKTableView保持位置不变不能完全保证内容的偏移位置。
如果一个内容较短的情况下依然会有偏移量的问题虽然我们可以通过填充空白内容来改善这个问题但又增加了很多工作量。
内容切换时没有平顺的效果。
为了尽可能的完善我们的吸顶效果我们尝试用UITableViewUICollectionView的组合来实现吸顶和左右滑动二种效果。
UKNestedScrollView()property(nonatomic,
(instancetype)initWithFrame:(CGRect)frame
{self.tableView.tableHeaderView
(void)addTabView:(UKTabItemView
addItemView:itemView];[self.contentViewArray
addObject:contentView];[self.collectionView
UKNestedScrollView包含一个UITableView[self
addSubview:self.tableView];[self.tableView
mas_makeConstraints:^(MASConstraintMaker
{make.left.right.top.bottom.equalTo(self);}];
NO;_tableView.showsVerticalScrollIndicator
forCellReuseIdentifier:CellId];}return
NO;_tableView.showsVerticalScrollIndicator
forCellReuseIdentifier:CellId];}return
SectionHeaderView包含UKTabView和UICollectionView
initWithFrame:self.frame];[_sectionHeaderView
addSubview:self.tabView];[_sectionHeaderView
addSubview:self.collectionView];}return
UICollectionViewScrollDirectionHorizontal;layout.itemSize
CGSizeMake(self.frame.size.width,
CGFLOAT_MIN;layout.minimumInteritemSpacing
collectionViewLayout:layout];_collectionView.pagingEnabled
NO;_collectionView.showsHorizontalScrollIndicator
registerClass:[UICollectionViewCell
forCellWithReuseIdentifier:CellId];}return
(CGFloat)tableView:(UITableView
heightForHeaderInSection:(NSInteger)section
viewForHeaderInSection:(NSInteger)section
(NSInteger)tableView:(UITableView
numberOfRowsInSection:(NSInteger)section
cellForRowAtIndexPath:(NSIndexPath
(NSInteger)collectionView:(UICollectionView
numberOfItemsInSection:(NSInteger)section
*)collectionView:(UICollectionView
cellForItemAtIndexPath:(NSIndexPath
dequeueReusableCellWithReuseIdentifier:CellId
forIndexPath:indexPath];UITableView
self.contentViewArray[indexPath.row];[contentView
removeFromSuperview];[cell.contentView
addSubview:contentView];[contentView
mas_makeConstraints:^(MASConstraintMaker
{make.left.right.top.bottom.equalTo(cell.contentView);}];return
(void)scrollViewWillBeginDragging:(UIScrollView
(void)scrollViewDidScroll:(UIScrollView
scrollView.contentOffset.x;NSInteger
offsetRatio:(width/self.frame.size.width
(void)scrollViewDidEndDecelerating:(UIScrollView
scrollView.contentOffset.x;NSInteger
setSelection:page];self.dragging
(void)scrollViewDidEndDragging:(UIScrollView
willDecelerate:(BOOL)decelerate
scrollView.contentOffset.x;NSInteger
setSelection:page];self.dragging
(void)onTabViewSelected:(UKTabView
collectionViewScrollToPosition:position];
}为了让UICollectionView内的手势能被UITableView接收需要在UKNestedTableView里面加上
(BOOL)gestureRecognizer:(UIGestureRecognizer
shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer
我们可以看到当列表滑动时两个列表都在滑动而且里面的内容的滑动更快。
这主要是因为例外两个列表都在滑动所以里面的列表其实是两个滑动距离相加所有我们需要在外面列表滑动时禁止里面列表的滑动。
self.tableView.contentOffset.y;//
记录当前页面偏移量方便后面禁止事件self.offsetArray[position]
numberWithFloat:scrollView.contentOffset.y];}
现在的效果已经基本满足了我们的需求有吸顶效果、能左右滑动、能记录列表偏移量内容滑动时也比较平顺了。
self.tableView.contentOffset.y;self.changed
numberWithFloat:scrollView.contentOffset.y];}}
self.originOffset;self.tableView.delegate
nil;self.tableView.contentOffset
self.offset);self.tableView.delegate
numberWithFloat:scrollView.contentOffset.y];}break;}position;}
作为专业的SEO优化服务提供商,我们致力于通过科学、系统的搜索引擎优化策略,帮助企业在百度、Google等搜索引擎中获得更高的排名和流量。我们的服务涵盖网站结构优化、内容优化、技术SEO和链接建设等多个维度。
| 服务项目 | 基础套餐 | 标准套餐 | 高级定制 |
|---|---|---|---|
| 关键词优化数量 | 10-20个核心词 | 30-50个核心词+长尾词 | 80-150个全方位覆盖 |
| 内容优化 | 基础页面优化 | 全站内容优化+每月5篇原创 | 个性化内容策略+每月15篇原创 |
| 技术SEO | 基本技术检查 | 全面技术优化+移动适配 | 深度技术重构+性能优化 |
| 外链建设 | 每月5-10条 | 每月20-30条高质量外链 | 每月50+条多渠道外链 |
| 数据报告 | 月度基础报告 | 双周详细报告+分析 | 每周深度报告+策略调整 |
| 效果保障 | 3-6个月见效 | 2-4个月见效 | 1-3个月快速见效 |
我们的SEO优化服务遵循科学严谨的流程,确保每一步都基于数据分析和行业最佳实践:
全面检测网站技术问题、内容质量、竞争对手情况,制定个性化优化方案。
基于用户搜索意图和商业目标,制定全面的关键词矩阵和布局策略。
解决网站技术问题,优化网站结构,提升页面速度和移动端体验。
创作高质量原创内容,优化现有页面,建立内容更新机制。
获取高质量外部链接,建立品牌在线影响力,提升网站权威度。
持续监控排名、流量和转化数据,根据效果调整优化策略。
基于我们服务的客户数据统计,平均优化效果如下:
我们坚信,真正的SEO优化不仅仅是追求排名,而是通过提供优质内容、优化用户体验、建立网站权威,最终实现可持续的业务增长。我们的目标是与客户建立长期合作关系,共同成长。
Demand feedback