OK, I developed a solution. When I detect a shaking movement (acceleration greater than 1.5 on the x axis), I start the timer and set BOOL to true. While BOOL is true, I am adding acceleration values. When the timer expires, I stop adding acceleration values ββand determine the direction of shaking by the sign of full acceleration.
- (void)accelerometer:(UIAccelerometer *)acel didAccelerate:(UIAcceleration *)aceler { if (fabsf(aceler.x) > 1.5) { shake = YES; NSTimeInterval myInterval = .75; [NSTimer scheduledTimerWithTimeInterval:myInterval target:self selector:@selector(endShake) userInfo:nil repeats:NO]; return; } if(shake) { totalG += aceler.x; } } - (void) endShake { shake = NO; int direction; if (totalG isLessThan 0) direction = 1; if(totalG isGreaterThan 0) direction = -1; [self changePageByShake:direction]; totalG = 0; }
Note: I was unable to get <and> characters for proper formatting in the code block above, so I replaced isLessThan and isGreaterThan for characters.
source share