iPhone模拟器总是产生两次摇动事件? (UIScrollview 不滚动第二个事件)
当我从 iPhone 模拟器的硬件菜单中选择“摇动手势”时,我的第一响应者总是收到两个摇动事件(中间有几毫秒)。
不幸的是,模拟器中的这两个事件导致 UIScrollview
出现问题,它应该滚动到特定位置 - 它会做什么,但仅限于第一个事件。
所以我有以下两个问题(以某种方式相互关联)...
问题 1
为什么模拟器会为一个“摇动手势”生成两个摇动事件?
注意:在真机上测试时不会发生这两个事件。真实 iPhone 上的摇晃总是会产生 一个 事件。
问题 2
有没有办法确保连续两次调用 [myScrollView setContentOffset:CGPointMake(x,0 )animated:YES];
两者都能正确执行吗?
注意:我发现有趣的是 - 当我在 setContentOffset
调用中将 animated:
设置为 NO
时,它完美地工作 - 两个调用都是被处决!不幸的是,这不是我正在开发的应用程序的一个选项。
顺便说一句,这个问题很容易重现。只需对 UIScrollview
进行两次带有动画的 setContentOffset
调用,然后仅查找第一个执行的...
[myScrollView setContentOffset:CGPointMake(300,0) animated:YES]; //this one works
[myScrollView setContentOffset:CGPointMake(100,0) animated:YES]; //this one not
提前致谢!
最好的, 马库斯
When I select "Shake Gesture" from the Hardware menu in the iPhone simulator, my first responder always receives two shake events (with a few milliseconds in between).
Unfortunately these two events in the simulator lead to a problem with an UIScrollview
that should scroll to a specific position - what it does, but only for the first event.
So I have the following two questions (that are connected to each other somehow)...
Question 1
Why does the simulator generate two shake events for one "Shake Gesture"?
Note: These two events do not occur when testing on the real device. A shake on the real iPhone always produces one event.
Question 2
Is there a way to make sure two subsequent calls of [myScrollView setContentOffset:CGPointMake(x,0) animated:YES];
get both executed properly?
Note: What I find interesting - when I set animated:
to NO
in the setContentOffset
call, it works flawlessly - both calls are executed! Unfortunately this is not an option for the App I'm working on.
Btw, the problem is easy to reproduce. Just make two calls of setContentOffset
with animation to an UIScrollview
and find only the first executed...
[myScrollView setContentOffset:CGPointMake(300,0) animated:YES]; //this one works
[myScrollView setContentOffset:CGPointMake(100,0) animated:YES]; //this one not
Thanks in advance!
Best,
Markus
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这与摇动的定义有关。您所说的震动可能与模拟器发送的运动量不同。例如,您在设备上的摇动可能是在任何轴上的大运动,而模拟器可能是 2 个大运动。您通常希望在代码中使用某种抖动超时或其他逻辑来处理此问题,以便多个事件不会被意外触发。你永远不会知道用户是否会摇晃一次或连续摇晃 5 次,因此你的逻辑应该能够处理所有可能的情况。
This has to do with the definition of a shake. What you may be calling a shake may be different from the amount of movement the simulator sends. For example, your shake on the device may be on big movement in any axis, whereas the simulator may be 2 big movements. You usually want to handle this in your code with some sort of shake timeout or other logic such that multiple event do not get fired undesirably. You will never know if a user will shake once or shake 5 times in a row, so your logic should be able to handle all possible cases.