iPhone 和模拟器中的 TouchMoved 行为
函数 touchesMoved
在 iPhone 和模拟器中的行为有所不同。
touchesMoved
函数的重复间隔(刷新率)比模拟器快得多。有没有办法处理差异?
The function touchesMoved
behaves differently in iPhone and simulator.
The repeating interval (refresh rate) of the function touchesMoved
is much faster than simulator. Is there a way to deal with the difference?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
人们经常发现这是一个问题,因为他们在 TouchMoved 处理程序中执行一些密集操作,并且当事件非常频繁地到达时,它会使界面显得滞后。
处理这个问题的一个相对简单的方法是:首先,在 TouchMoved 处理程序中,将触摸位置存储在一个变量中,该变量表示跟踪手指的任何位置。
立即从 TouchMoved 处理程序返回。创建一个 NSTimer 对象并将您的视图控制器设置为它的委托,并让它执行您的 TouchMoved 处理程序中的任何重新绘制/视图移动行为。因此,无论 TouchMoved 事件之间的时间间隔如何,您都会获得近乎恒定的移动。
如果您真的很高级,您可以使用自定义 NSRunLoop 而不是使用计时器,但这超出了我在这里可以解释的范围:) 总体思路是:不要在触摸事件处理程序中执行所有操作。
Often people are finding this to be a problem because they are doing something intensive in the touchesMoved handler and when events arrive very frequently, it makes the interface appear to lag.
A relatively simple way to deal with this is: First of all, in the touchesMoved handler, store the touch position in a variable that represents the position of whatever is tracking the finger.
Return from the touchesMoved handler immediately. Create an NSTimer object and set your view controller as a delegate of it and have that do whatever re-drawing/view moving behaviour used to be in your touchesMoved handler. Thus, you get a near constant movement regardless of the time between touchesMoved events.
If you're really advanced you can use a custom NSRunLoop instead of using a timer, but that's more than I can explain here :) The general idea is: don't be doing everything in the touch event handlers.