如何知道 CollectionView 中 Header 的特定部分是否滚出屏幕边界?
How to know if a particular part of Header in CollectionView is scrolled out of Screen bounds?
我想在我的段控件超出屏幕边界时立即收到回调或通知。我的 collection 视图在顶部有一个自定义 header 视图。
过去,当我的 Header 视图中只有 1 个 UIElement 时,我使用了这些方法
func collectionView(UICollectionView, willDisplaySupplementaryView: UICollectionReusableView, forElementKind: String, at: IndexPath)
和
func collectionView(UICollectionView, didEndDisplayingSupplementaryView: UICollectionReusableView, forElementOfKind: String, at: IndexPath)
实现此回调以便我可以在发生这种情况时调用我的特定函数。
但我的 header 现在有一些更复杂的 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
}
}
我想在我的段控件超出屏幕边界时立即收到回调或通知。我的 collection 视图在顶部有一个自定义 header 视图。
过去,当我的 Header 视图中只有 1 个 UIElement 时,我使用了这些方法
func collectionView(UICollectionView, willDisplaySupplementaryView: UICollectionReusableView, forElementKind: String, at: IndexPath)
和
func collectionView(UICollectionView, didEndDisplayingSupplementaryView: UICollectionReusableView, forElementOfKind: String, at: IndexPath)
实现此回调以便我可以在发生这种情况时调用我的特定函数。
但我的 header 现在有一些更复杂的 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
}
}