每隔一段时间比较变量的值
嘿,我在以特定时间间隔将 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
你想用这个做什么?使用键值观察来观察一个或两个值何时发生变化是否更有意义?
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?
查看 NSTimer 文档。它做你想做的事。
Take a look at the NSTimer documentation. It does what you want.
正如 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.