【发布时间】:2020-04-09 03:17:19
【问题描述】:
我有 UICollectionView,里面有单元格。除了一件事,一切都很好。
在键盘外观动画期间,即将离开屏幕的顶部单元格会在没有任何动画的情况下消失在原地https://www.youtube.com/watch?v=hMt6DiJD5KU
我尝试实现finalLayoutAttributesForDisappearingItem,但没有任何效果。
还尝试在layoutAttributesForElementsInRect 中扩展rect
override func layoutAttributesForElements(in rect: CGRect) -> [UICollectionViewLayoutAttributes]? {
let rect = CGRect(x: rect.minX, y: rect.midY - 312, width: rect.width, height: rect.height + 312)
return itemAttributesCache.filter { $0.frame.intersects(rect) }
}
但也没有运气。
我找到的唯一可行的解决方案是将屏幕上方的UICollectionView.frame 扩展到键盘高度,并将UICollectionView.contentInset.top 设置为键盘高度。它有效,但绝对丑陋。
有什么解决办法吗?
【问题讨论】:
-
finalLayoutAttributesForDisappearingItem被调用用于对应于从集合视图中移除的项目的单元格,而不是用于离开屏幕的单元格。如果您可以提供一个示例项目,其中包含布局实现和发生的问题,将会更容易为您提供帮助。 -
您是否使用任何 SDK(如 IQKeyboardManager)来处理您的键盘操作?
标签: ios objective-c swift uicollectionview uicollectionviewlayout