Loading

Tuesday, August 24, 2010

Detect Shake in iPhone

1. in .h File --->#define kAccelerationThreshold 2.2

2. include UIAccelerometerDelegate

3. in .m File --> ViewDidload -->[[UIAccelerometer sharedAccelerometer] setDelegate:self];

4. #pragma mark -
#pragma mark Shake event

- (void)accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration *)acceleration
{
if (fabsf(acceleration.x) > GlobalRate || fabsf(acceleration.y) > GlobalRate || fabsf(acceleration.z) > GlobalRate)
{
// Your Code Here
}
}

No comments:

Post a Comment