Shake gesture not working

I use the code to detect jitter, and this code works on the device, but when I use the gesture trick on the simulator, why doesn't it work?

I use below code to 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)
            ...
}
+3
source share
3 answers

Take a look at the motionEnded method: the UIResponder method. You can implement motionEnded in your window, view, or view controller to detect vibrations, for example:

- (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event 
{
    if (event.type == UIEventSubtypeMotionShake) 
    {
        // your code here

    }
}

In my application, I needed a shake handler for the entire application. Therefore, I have subclassed UIWindow (my application has one window, like most), and put the handler in this subclass.

+5
source

"The Shake Gesture" ( ) - , , iOS. , didAccelerate . ( , ) , , .

+2

, , . (, ..). shake, , . , . .

+1

Source: https://habr.com/ru/post/1775195/


All Articles