我有一个要用作网格的 UICollectionView。当我收到一个有序的对时,我想将一个 CAShapeLayer 圆圈移动到适当的位置。我有 400 个 UICollectionView 单元格组成一个 20x20 的网格 (+, +)。有没有办法用 UICollectionView 做到这一点?
这是我的网格的样子......
绿点代表有序对 (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/