ios - 类似于 CGPoint 的类,但带有整数(用于表示网格中的位置)

标签 ios objective-c grid

iOS 中是否有内置类,可用于表示网格中的位置?

即类似于 CGPoint,但使用整数成员而不是 float 。

我在 CGGeometry Reference 中搜索过和其他文档,但找不到这样的类(很难用这样的关键字搜索)。

我知道我可以自己创建自定义类,但我希望有一个有用的“内置”类和很好的方法。

我需要它 a word game表示图 block 位置:

app screenshot

最佳答案

正如 Martin R 指出的那样,CGPoint 是一个 struct ,不是一个类(class)。话虽这么说,没有内置的方法。您可以在整个代码中相应地使用 CGPoint 进行强制转换,或者您可以像这样定义自己的结构:

struct CGIntegerPoint {
    NSInteger xPos;
    NSInteger yPos;
};

typedef struct CGIntegerPoint CGIntegerPoint;

CG_INLINE CGIntegerPoint CGIntegerPointMake(NSInteger x, NSInteger y) {
    CGIntegerPoint point;
    point.xPos = x;
    point.yPos = y;
    return point;
}

这现在为您提供了一个新的声明类型 CGIntegerPoint,以及一个相应的静态内联函数 CGIntegerPointMake(),它接受两个参数 (x,y) 并返回一个 CGIntegerPoint。

注意:将来,您可能会发现在 Xcode 中按住命令单击类型会很有帮助。这样做会跳转到类型的定义,在本例中,这也是它的实现。

关于ios - 类似于 CGPoint 的类,但带有整数(用于表示网格中的位置),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22879657/

相关文章:

grid - Kendo UI Grid 导出到 Excel/PDF 不适用于 IE9

ios - 摆脱临时保存的 managedObjectContext

ios - Clocationmanager Didupdatelocation 委托(delegate)在没有互联网的情况下不会被调用

ios - 为什么不是我的所有代码都在我的 findObjectsInBackgroundWithBlock :^ being executed?

ios - 如何将另一个按钮与右侧导航项 (UIBarButtonItem) 对齐?

ios - UIpagecontrol 需要动画从右到左

ios - 使用临时配置编译应用失败,但调试配置在Xcode 5.1中有效

ios - 创建自定义 Collection View 布局

c# - 动态行定义高度

css - telerik asp.net mvc grid - 如何在悬停时设置选定行的样式