每隔一段时间比较变量的值

发布于 2024-08-04 03:09:58 字数 147 浏览 2 评论 0原文

嘿,我在以特定时间间隔将 CGPoint(具有两个整数的结构:x 和 y)的值与另一个值进行比较时遇到问题。

一种称为位置,具有光标所在位置的值。每隔半秒左右,我想看看它是否改变了。我该怎么做?语言是 Objective-C(所以 C++/C 的东西应该可以工作)

Hey I have a problem comparing the value of a CGPoint (struct with two ints: x and y) with another at certain time intervals.

One is called location and has the value of where the cursor is. Every half a second or so, I want to see if it changed. How do I do this? The language is Objective-C (so C++/C stuff should work)

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

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

发布评论

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

评论(3

荆棘i 2024-08-11 03:09:58

你想用这个做什么?使用键值观察来观察一个或两个值何时发生变化是否更有意义?

What are you trying to do with this? Would it make more sense to use Key Value Observing to observe when one or both values change?

无法回应 2024-08-11 03:09:58

查看 NSTimer 文档。它做你想做的事。

Take a look at the NSTimer documentation. It does what you want.

笑忘罢 2024-08-11 03:09:58

正如 CGGeometry 文档中所述,Apple 提供了一个函数 CGPointEqualToPoint() 来执行此操作。您将有一个 CGPoint 变量来存储旧值并将其与获得的新值进行比较。

As noted in the CGGeometry docs, Apple provides a function, CGPointEqualToPoint(), for doing just this. You would have a CGPoint variable that stores the old value and compare it to the new value you get.

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