ios - 如何知道 CollectionView 中 Header 的特定部分是否滚出屏幕边界?

标签 ios swift xcode swift3 uicollectionview

我想在我的段控件超出屏幕边界时立即获得回调或通知。我的 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 控件超出屏幕截图的屏幕边界时立即收到通知或回调? enter image description here

最佳答案

您是否尝试过如下实现 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/

相关文章:

ios - 如何向 UIActivityViewController 添加自定义按钮?

ios - 在导航 Controller 中的 View 之间跳转

ios - Swift:UIScrollView 和 UIControl - 添加目标 | addGestureRecognizer - 未按预期工作

ios - ios中sendEvent和Send Action的区别

ios - 子 ViewControllers 数组在具有各种容器的 View Controller 中是否具有特定顺序?

ios - 尝试选择尚未添加的注释

swift - 在 Swift 中使用泛型实例化 Realm 对象

ios - 附加PathComponent后路径不同(_ :)

objective-c - 不同目标中的两个同名 Objective C 文件,由 Swift 类使用

ios - Xcode 调试器崩溃 (Xcode 6.1/LLDB/Yosemite)