- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我目前有一个 UICollectionView
使用 UICollectionViewCompositionalLayout
.我想在滚动/滚动停止时为当前可见单元格中的一些 View 设置动画。
不幸的是,它似乎在设置 orthogonalScrollingBehavior
除了 .none
之外的任何部分劫持UICollectionView
随行 UIScrollView
委托(delegate)方法。
想知道是否有任何当前的解决方法? 获取分页行为和UIScrollView
代表?
设置布局
enum Section {
case main
}
override func awakeFromNib() {
super.awakeFromNib()
collectionView.collectionViewLayout = createLayout()
collectionView.delegate = self
}
func configure() {
snapshot.appendSections([.main])
snapshot.appendItems(Array(0..<10))
dataSource.apply(snapshot, animatingDifferences: false)
}
private func createLayout() -> UICollectionViewLayout {
let leadingItem = NSCollectionLayoutItem(
layoutSize: NSCollectionLayoutSize(
widthDimension: .fractionalWidth(1.0),
heightDimension: .fractionalHeight(1.0))
)
leadingItem.contentInsets = .zero
let containerGroup = NSCollectionLayoutGroup.horizontal(
layoutSize: NSCollectionLayoutSize(
widthDimension: .fractionalWidth(1.0),
heightDimension: .fractionalHeight(1.0)
),
subitems: [leadingItem])
let section = NSCollectionLayoutSection(group: containerGroup)
section.orthogonalScrollingBehavior = .groupPaging // WOULD LIKE PAGING & UISCROLLVIEW TO ALSO BE FIRED
let config = UICollectionViewCompositionalLayoutConfiguration()
config.scrollDirection = .horizontal
let layout = UICollectionViewCompositionalLayout(section: section, configuration: config)
return layout
}
extension SlidingCardView: UICollectionViewDelegate {
func collectionView(_ collectionView: UICollectionView, willDisplay cell: UICollectionViewCell, forItemAt indexPath: IndexPath) {
// THIS IS FIRED BUT UISCROLLVIEW METHODS NOT
}
func scrollViewDidEndDecelerating(_ scrollView: UIScrollView) {
print(111)
}
func scrollViewWillBeginDragging(_ scrollView: UIScrollView) {
print("1111111")
}
}
最佳答案
设置orthogonalScrollingBehavior
到一个部分,嵌入一个内部 _UICollectionViewOrthogonalScrollerEmbeddedScrollView
它处理部分中的滚动。这个内部 ScrollView 作为 subview 添加到您的 Collection View 中。
当您将自己设置为 delegate
在您的收藏 View 中,您应该会收到 ScrollView 委托(delegate)回调 但仅限 对于主 Collection View ,它在部分之间滚动,而不是在部分中的项目之间滚动。由于内部 ScrollView (也可能是 collectionViews,不确定)是完全不同的实例,并且您没有将自己设置为它们的委托(delegate),因此您不会收到它们的回调。
据我所知,不应该有官方方式从处理部分滚动的内部 ScrollView 接收这些回调。
但是如果你很好奇并且想尝试一下,你可以使用这个'hacked' collectionView 类:
import UIKit
final class OrtogonalScrollingCollectionView: UICollectionView {
override var delegate: UICollectionViewDelegate? {
get { super.delegate }
set {
super.delegate = newValue
subviews.forEach { (view) in
guard String(describing: type(of: view)) == "_UICollectionViewOrthogonalScrollerEmbeddedScrollView" else { return }
guard let scrollView = view as? UIScrollView else { return }
scrollView.delegate = newValue
}
}
}
}
关于ios - 设置 UICollectionViewCompositionalLayout 时未调用 UIScrollView 委托(delegate)方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58791121/
我希望我的 UICollectionView 的最小项目大小为 150x150。我希望组合布局确定有多少 150x150 单元格可以安全地适应环境,然后在必要时从 150x150 扩大尺寸以填补空白,
我目前面临着组合布局的问题,这也可以在 Apple's example 中看到。 -> ConferenceNewsFeedViewController。项目高度设置为 .estimated(100)
我想在我的 UICollectionView 中有几个部分。其中一个应该有包含文本的项目。使用“经典” collectionView 方法显示在同一行中的项目数取决于项目宽度。如果项目不适契约(Con
我有一个用于标签 View 的基本组合布局。单元格只包含一个带有自动布局约束的标签。目标是在垂直和水平方向自动调整单元格大小以适合标签。对于组合布局,当我分别将 NSCollectionLayoutG
我已经成功地使用 UICollectionViewCompositionalLayout 创建了一个网格布局。 .但是,我找不到确保 UICollectionViewCell 的聪明方法。当它们的高度
在视频中 Advances in Collection View Layout - WWDC 2019 ,Apple 引入了新的“正交滚动行为”功能。我有一个几乎与 OrthogonalScrolli
我正在尝试使用 UICollectionViewCompositionalLayout 创建一个“标签云”部分 我想要一个全宽的部分,然后是一个以这种方式包裹的部分 必备 人力资源 , 财务健康 和
是否可以使用 UICollectionViewCompositionalLayout 创建包含多个部分的水平滚动 Collection View ? 我想创建一个类似于表情符号键盘的布局,它有多个部分
我正在尝试在 iOS13 上使用新的 UICollectionViewCompositionalLayout。我想显示两种不同的单元格类型,但我希望布局系统自动调整单元格的大小。我想利用 NSColl
我正在构建一个带有 Collection View 的 View Controller ,使用(有点)新的可区分数据源和可组合的 Collection View 布局。我制作了自己的 Section
我有一个 UICollectionView,其中我使用 UICollectionViewCompositionalLayout 布置了两个部分(一个水平滚动,一个垂直滚动)。我将其与 UICollec
我使用 UICollectionViewCompositionalLayout。所有部分都有圆形背景。背景只是添加到所有部分 let background = NSCollectionLayo
我使用 UICollectionViewCompositionalLayout。所有部分都有圆形背景。背景只是添加到所有部分 let background = NSCollectionLayo
有几天我无法弄清楚如何使用 UICollectionViewCompositionalLayout 制作像屏幕截图中那样的 Collection View 。谁能帮忙? Image!!!! 最佳答案
我的布局代码非常简单,你会在每一篇关于新组合布局的教程或文章中看到。 func createLayout() -> UICollectionViewLayout { let itemSiz
目前,我有一个单行水平 UICollectionView与 UICollectionViewCompositionalLayout [All] [Calendar] [Home2] [Work3] [
我在 上遇到了一个奇怪的布局问题iOS 14.3 Collection View 使用 UICollectionViewCompositionalLayout在我的情况下与 UICollectionV
我目前有一个 UICollectionView使用 UICollectionViewCompositionalLayout .我想在滚动/滚动停止时为当前可见单元格中的一些 View 设置动画。 不幸
我是一名优秀的程序员,十分优秀!