iPhone SDK:如何存储触摸事件期间生成的坐标对?

发布于 2024-07-17 12:19:58 字数 398 浏览 8 评论 0原文

我正在尝试为 iPhone 创建一个旋转对象。 我用它计算所有的三角函数。 问题是,对于我的项目,每次手指围绕中心点拖动超过 30 度时,我都需要让程序重置 x 和 y。 每当我将变量链接到 TouchMoved 函数中当前位置的 x 和 y 时,它们就会永久链接并随着拖动事件不断变化,而不是保持不变并每 30 度更新一次。 有没有办法静态存储 x 和 y?

凯洛亚·卡达诺, 已经这样做了,它仍然链接和更新。 代码: currentpoint = [触摸locationInView:self.view]; 当起点和当前点之间的角度 >= 30 度时 设置 altpoint = currentpoint,我使用 CGPointMake 做到了这一点,但它不起作用。 替代点不断更新到当前点

I'm trying to create a rotating object for the iPhone. I have it calculating all the trig. The problem is that for my project I have need to have the program reset the x and y every time a finger is dragged more over then 30 degrees around the center point. Whenever I link a variable to the x and y of the current location within the touchesMoved function they link permanently and continually change along with the drag event instead of staying constant and updating every 30 degrees. Is there a way to statically store an x and y?

Kailoa Kadano,
already did that and it still linked and updated.
Code:
currentpoint = [touch locationInView:self.view];
when angle between startpoint and currentpoint >= 30 degrees
set altpoint = currentpoint, I did that using CGPointMake and it didn't work.
altpoint continually updated to currentpoint

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

沙沙粒小 2024-07-24 12:19:58

使用 CGPoint 结构。

CGPoint 点 = CGPointMake(1,2);
点.x // 1
点.y // 2

Use the CGPoint struct.

CGPoint point = CGPointMake(1,2);
point.x // 1
point.y // 2

稚气少女 2024-07-24 12:19:58

请务必在您的类 .h 文件中声明 CGPoint startPoint,然后使用以下内容更新您的 TouchBegan 实现中的值:

startPoint = CGPointMake(point1.x, point1.y);

正如上面 Kailoa 所指定的。 然后,在 TouchMoved 实现中,您可以检查新点的间隔是否超过 30 度,如果是,则更新 startPoint。

如果上述内容不是您想要的,请发布更多详细信息/示例代码。

Be sure to declare CGPoint startPoint in your classes .h file, and then update the value within your touchesBegan implementation with:

startPoint = CGPointMake(point1.x, point1.y);

As specified by Kailoa above. Then, in your touchesMoved implementation, you can do a check to see if the new point is more than 30 degrees separation, and if so, update startPoint.

If the above isn't what you are looking for, please post more details/example code.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文