I use a code for detect shake and this code work on device but when i use shake gesture on simulator doesn't work why?
i use below code for detect it
#define kAccelerationThreshold 2.2
#define kUpdateInterval (1.0f/10.0f)
- (void)accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration *)acceleration
{
if (fabsf(acceleration.x) > kAccelerationThreshold || fabsf(acceleration.y) > kAccelerationThreshold || fabsf(acceleration.z) > kAccelerationThreshold)
...
}
Have a look at the motionEnded: method of UIResponder. You can implement motionEnded on your window, view, or view controller to detect shakes, like this:
- (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event
{
if (event.type == UIEventSubtypeMotionShake)
{
// your code here
}
}
In my app I needed an application-wide shake handler. So I subclassed UIWindow (my app has one window, as do most) and put the handler in that subclass.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With