繁体   English   中英

比较CGPoint和NSNumber

[英]Comparing CGPoint and NSNumber

这是我的第一篇文章,请客气:)

我到处寻找解决方案,但似乎找不到。 问题可能是以Google会返回有用结果的方式提出问题。

因此,我有一个NSMutableArray(称为boardColCoords),而我有CGPoint(称为touchLocation)。 我想比较两者,以便可以将UIImageView位置捕捉到boardColCoords数组中的适当坐标。

以下是相关代码:

UITouch *touch = [[event allTouches] anyObject];
CGPoint touchLocation = [touch locationInView:self.view];

NSNumber *boardSquareX = [boardColCoords objectAtIndex:i];

if (touchLocation.x - boardSquareX <= 12)
{
}

我知道最终将必须更改12,但是我只想先使减法开始工作。 我得到的具体错误是:

无效的二进制二进制操作数(“ CGFloat”(又名“ float”)和“ NSNumber *”)。

NSNumber是一个包装器,您必须使用floatValue之类的“提取”它的值来进行比较:

if (touchLocation.x - [boardSquareX floatValue] <= 12)

要从NSNumber获取浮点值,您需要

[boardSquareX floatValue];

您需要从boardSquareX提取原始编号。

if (touchLocation.x - [boardSquareX floatValue] <= 12)
{
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM