ios - 使用 UICollectionView 创建网格系统

标签 ios swift gridview uicollectionview

我有一个要用作网格的 UICollectionView。当我收到一个有序的对时,我想将一个 CAShapeLayer 圆圈移动到适当的位置。我有 400 个 UICollectionView 单元格组成一个 20x20 的网格 (+, +)。有没有办法用 UICollectionView 做到这一点?

这是我的网格的样子......

UICollectionView Grid

绿点代表有序对 (12, 2)。通过猜测和检查 CGPoint 与 (12, 2) 对应的内容,我在正确的位置找到了点。

如有任何帮助或建议,我们将不胜感激! 提前致谢!

最佳答案

假设您的网格到达 UICollectionView 的边缘,这样的事情应该会起作用。您可能需要将 CGPoint 调整为圆宽度的一半。

let width = collectionView.bounds.width

// dimensions of the grid
let xdim: CGFloat = 20
let ydim: CGFloat = 20

// the grid coordinates of your point
let x: CGFloat = 12
let y: CGFloat = 2

let point = CGPoint(x: x * width / xdim, y: (ydim - y) * width / xdim)

关于ios - 使用 UICollectionView 创建网格系统,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49843518/

相关文章:

iOS8:当手机旋转到横向时如何显示不同的 View Controller ?

swift - 核心数据 : Loading Integers out of a File

android - 在不同的 Activity 或 Fragment 之间共享数据的正确方法是什么?

android - 图像显示为gridview

ios - presentModalViewController 导致神秘的僵尸

ios - 有没有办法在 iOS 中动态更改我的应用程序的图标?

ios - Appium 测试 - "Sdk 9.3 was not in the list of simctl sdks"

Swift:如何在显示之前获取 subview 的大小?

generics - Swift - 通用类型类/结构的扩展?

c# - 如何允许对 gridview 进行排序?