ios - 如何知道 CollectionView 中 Header 的特定部分是否滚动到屏幕边界之外?
问题描述
我想在我的段控件超出屏幕范围时立即获得回调或通知。我的收藏视图顶部有一个自定义标题视图。
过去,当我的 Header 视图中只有 1 个 UIElement 时,我使用了这些方法
func collectionView(UICollectionView, willDisplaySupplementaryView: UICollectionReusableView, forElementKind: String, at: IndexPath)
和
func collectionView(UICollectionView, didEndDisplayingSupplementaryView: UICollectionReusableView, forElementOfKind: String, at: IndexPath)
实现这个回调,这样我就可以在发生这种情况时调用我的特定函数。
但我现在有一个更复杂的标题,只有几个 UIElements。有没有一种方法可以在 Segment 控件超出屏幕截图的屏幕范围时立即获得通知或回调?
解决方案
您是否尝试过如下实施scrollViewDidScroll
方法?
var isSegmentedHidden = false
func scrollViewDidScroll(_ scrollView: UIScrollView) {
if scrollView.contentOffset.y < 50.0 && isSegmentedHidden{ //Here 50.0 is the height of your segmented control plus vertical padding if any.
isSegmentedHidden = false
//Call your function here, once segmented control is visible
}
if scrollView.contentOffset.y >= 50.0 && isSegmentedHidden == false{ //Here 50.0 is the height of your segmented control plus vertical padding if any.
isSegmentedHidden = true
//Call your function here, once segmented control is invisible
}
}
推荐阅读
- excel - 在循环中使用 Range 选择两个不同的单元格
- ruby-on-rails - 如何访问 Ruby splat 参数?
- scala - 运行测试时未捕获的异常:java.lang.NoClassDefFoundError: scala/collection/mutable/ArrayOps$ofRef
- android - build.gradle 不工作。红色下划线但没有掉毛错误
- scala - 如何修复 Akka HTTP 中的无限重定向?
- java - 如何在添加了 jackson-dataformat-xml 的情况下将默认 MessageConverter 设置为 JSON?
- java - 为单元测试创建样本数据列表
- c# - 如何修复“值无效”错误cshtml?
- python - AttributeError:“DataFrame”对象没有属性“plot_coordinates”
- mysql - 在查询中使用分组时如何包含字段相关数据