Reusable Snippets

Shake reset

Shake reset. Actually the snippet really just for responding to a shake motion. The snippet was used to reset an image, but can be changed out to respond to anything. Another objective-c snip. There a comment in the block of code below where the change can occur.

--

- (void)motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event {

}

// Shaking here resets an image but it can do anything, just change out self
// resetImage to something else.
- (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event {
if (motion = UIEventSubtypeMotionShake ) {
[self resetImage];
}
}

- (void)motionCancelled:(UIEventSubtype)motion withEvent:(UIEvent *)event {

}

Filed under  //   Objective- C   iPhone   motion  
Posted May 6, 2010