ios - 观察 UICollectionView 的 visibleCells 数组的变化

标签 ios swift uicollectionview key-value-observing

我想知道 UICollectionViewvisibleCells 属性的计数何时更改。 我知道我可以观察继承自 NSObject 的对象,只要我想观察的属性是 dynamic。例如:

let view = UIView()
view.observe(\.isHidden, options: .new) { view, change in
  print(change.newValue)
}

如何以类似的方式观察 UICollectionViewvisibleCells

最佳答案

我不太确定 KVO 会在这方面为您提供帮助。但是 collectionView 确实有委托(delegate)方法 collectionView(:willDisplay:forItemAt:) collectionView( :didEndDisplaying:forItemAt:)您可以使用它来推断可见单元格的变化。您也可以签到scrollViewDidScroll(_:)

关于ios - 观察 UICollectionView 的 visibleCells 数组的变化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47659761/

相关文章:

ios - 扫描二维码后如何进入新的 View Controller ?

swift - 如何将 subview (如标签)添加到已经有 subview 的 UIViewController 主视图?

ios - 错误 : type may not reference itself as a requirement associatedtype Suffix: SuffixableContainer where Suffix. 项目 == 项目

ios - 完全移动到其他 View 并且不允许在 SwiftUI 中返回

ios - UICollectionView 底部的 UIRefreshControl(加载更多数据)

ios - 错误 : Target failed to run: Permission to debug com. apple.Preferences 被拒绝

ios - FireBase PhoneAuth 线程 1 : Fatal error: Unexpectedly found nil while unwrapping an Optional value

ios - Swift - 为 UICollectionView 中的每个单元格创建单独的 UIView

ios - 将图像数组添加到 Collection View - swift

ios 理解我的 block 中的 SIGABRT