开发者

iPhone Simulator always generates two shake events? (UIScrollview not scrolling for second event)

When I select "Shake Gesture" from the Hardware menu in the iPhone simulator, my first responder always receives two shake events (开发者_Go百科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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜