English 中文(简体)
目标C:比较CG Points
原标题:Objective C: Comparing CGPoints

I am trying to do an if-else statement for my CGPoints how would I be able to do that, I tried this code...

if (point1 != point2)
{
       //statement
}

I m

<编码> 双亲表达的无效歌剧......

感谢!

最佳回答

转而使用<代码>CGPointEqual ToPoint。

if (!CGPointEqualToPoint(p1,p2))
{
  //statement
}
问题回答

您可以:

if (!CGPointEqualToPoint(point1, point2)) {
....
}

浮标(因此,CGFloats)是一种微滴滴滴滴,因为有时你希望这些浮体被视为平等,但会把微粒重新.。 如果你想进行“fu”比较,你可以做这样的事:

if (fabsf(point1.x - point2.x) > 0.0001f || fabsf(point1.y - point2.y) > 0.0001f) {
...
}

这种检查可以发现,点1和点2的x &、及部件的差别大于0.0001(完全任意的编号,可以是你希望的准确度)。

我将建议使用以下职能:(从Ampap Docs)

www.un.org/Depts/DGACM/index_russian.htm Returns?

bool CGPointEqualToPoint (CGPoint point1, CGPoint point2);

参数

要点1: 第一个审查点。

要点2: 第二点审查。

Return Value true if the two specified points are the same; otherwise, false.

http://developer.apple.com/library/mac/#DOCUMENTATION/GraphicsImaging/Reference/CGGeometry/Reference/ Reference.html。 CGGeometry Reference





相关问题
List Contents of Directory in a UITableView

I am trying to list the contents of Ringtones directory in a TableView, however, I am only getting the last file in the directory in ALL cells, instead of file per cell. This is my code: - (...

iPhone NSUserDefaults persistance difficulty

In my app i have a bunch of data i store in the NSUserdefaults. This information consists of an NSObject (Object1) with NSStrings and NSNumbers and also 2 instances of yet another object (Object2). ...

Writing a masked image to disk as a PNG file

Basically I m downloading images off of a webserver and then caching them to the disk, but before I do so I want to mask them. I m using the masking code everyone seems to point at which can be found ...

Resize UIImage with aspect ratio?

I m using this code to resize an image on the iPhone: CGRect screenRect = CGRectMake(0, 0, 320.0, 480.0); UIGraphicsBeginImageContext(screenRect.size); [value drawInRect:screenRect blendMode:...

Allowing interaction with a UIView under another UIView

Is there a simple way of allowing interaction with a button in a UIView that lies under another UIView - where there are no actual objects from the top UIView on top of the button? For instance, ...

热门标签