我想在我的段控件超出屏幕边界时立即获得回调或通知。我的 Collection View 在顶部有一个自定义标题 View 。
过去,当我的 Header View 中只有 1 个 UIElement 时,我使用了这些方法
func collectionView(UICollectionView, willDisplaySupplementaryView: UICollectionReusableView, forElementKind: String, at: IndexPath)
和
func collectionView(UICollectionView, didEndDisplayingSupplementaryView: UICollectionReusableView, forElementOfKind: String, at: IndexPath)
实现此回调,以便我可以在发生这种情况时调用我的特定函数。
但是我现在有一些更复杂的 header ,其中包含更多的 UIElement。有没有一种方法可以让我在 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
}
}
关于ios - 如何知道 CollectionView 中 Header 的特定部分是否滚出屏幕边界?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53200662/