- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我需要在纵向模式下保持 UICollectionViewCell 居中对齐。
最终结果应该是这样的: animation
我正在使用此代码来执行此操作:
override public func targetContentOffset(forProposedContentOffset proposedContentOffset: CGPoint, withScrollingVelocity velocity: CGPoint) -> CGPoint {
var layoutAttributes: Array = layoutAttributesForElements(in: collectionView!.bounds)!
if layoutAttributes.count == 0 {
return proposedContentOffset
}
var firstAttribute: UICollectionViewLayoutAttributes = layoutAttributes[0]
for attribute: UICollectionViewLayoutAttributes in layoutAttributes {
if attribute.representedElementCategory != .cell {
continue
}
if((velocity.x >= 0.0 && attribute.center.x > firstAttribute.center.x) ||
(velocity.x <= 0.0 && attribute.center.x < firstAttribute.center.x)) {
firstAttribute = attribute;
}
}
return CGPoint(x: firstAttribute.center.x -
collectionView!.bounds.size.width * 0.5, y: proposedContentOffset.y)
}
这适用于所有单元格,除了最后一个单元格在滚动时没有居中对齐。
实际结果:
有什么办法可以解决这个问题吗?
最佳答案
我发现如果我设置
collectionView.isPagingEnabled = true
它会破坏中心单元格设置。一旦我将其关闭,一切又恢复正常了
关于ios - "targetContentOffset"UICollectionViewFlowLayout 无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45614617/
为什么这不起作用?我在 targetContentOffset->y = -50.0f; 设置了一个断点,并且它被击中,不知道为什么它没有任何效果。 是的寻呼 = 否。 - (void)scrollV
我需要在纵向模式下保持 UICollectionViewCell 居中对齐。 最终结果应该是这样的: animation 我正在使用此代码来执行此操作: override public func ta
我正在编写一个自定义的 UICollectionViewFlowLayout,它覆盖了 targetContentOffset(forProposedContentOffset:),以便在用户缩放时提
我希望 UIScrollView 始终滚动回特定点。我通过写作实现了它: - (void)scrollViewWillEndDragging:(UIScrollView *)scrollView
我使用以下代码在我的应用中实现了大标题: if #available(iOS 11.0, *) { navigationController?.navigationBar.pr
documentation声明它是 points(每秒,我假设)?但是,我得到的值在 (.5, 3.5) 范围内。然后 ScrollView 在停止之前移动了数百个点。实际初速度应该相差几个数量级。
我正在为 targetContentOffset 设置一个新值在 scrollViewWillEndDragging(_:withVelocity:targetContentOffset:)在 UIT
我有一个实现分页的 Collection View ,这就是为什么我在自定义 UICollectionViewFlowLayout 中覆盖 targetContentOffset 来处理它。当通过用户
我在一个 View Controller 上有两个 UITableViews( View Controller 是他们的代表)。其中之一将取决于 scrollViewWillEndDragging:w
在我的 UIViewController 中,我有一个 UICollectionView。委托(delegate)设置正确。它工作正常。 isPagingEnabled 设置为 true。但是现在我想
我正在尝试实现一个自定义标签栏,它是可滚动的并且在每个标签栏项目上都有分页。为此,我正在使用代理 scrollViewWillEndDragging:withVelocity:targetConten
如何用 Swift 编写此代码? 更新:发布了我试图转换的方法,最初发布了一个不同的方法,这不是我试图隐藏的方法 这适用于 Objective C,但不适用于 Swift。当我尝试将 ceilf 和
我希望我的垂直 UIScrollView 仅在用户向上滚动时停在最大内容偏移处,或者在用户向下滚动时停在最小内容偏移处。 我正在使用以下两个函数 func targetContentOffset(fo
我是一名优秀的程序员,十分优秀!