0

I have a bunch of XIB files and I would like it so if the user shakes the device, one of the XIBs are loaded onto the screen and I was wondering how I could go about doing this.

Thanks a lot in advance! Daniel

1 Answers1

0

There are 3 methods you can use

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

I use

-(void)motionEnded:(UIEventSubtype)motion 
         withEvent:(UIEvent *)event
{
    // show your view
    [self presentModalViewController:yourView animated:YES];
}

If you want to handle more than 1 shake event check out How do I detect when someone shakes an iPhone?

Community
  • 1
  • 1
syclonefx
  • 2,830
  • 1
  • 21
  • 24
  • How would one load an XIB with each shake, what if statement could be used? For example, if(SHAKEAMOUNTTHING == 1) {NSLog@"Shake 1);} else if(SHAKEAMOUNTTHING == 2) {NSLog@"Shake 2);} –  Oct 15 '11 at 19:26
  • The code I posted above will only handle 1 event. I'm not sure if there is a way to count the shaking event with that code. I updated the code to show displaying 1 view. You might want to check out this post: [http://stackoverflow.com/questions/150446/how-do-i-detect-when-someone-shakes-an-iphone](http://stackoverflow.com/questions/150446/how-do-i-detect-when-someone-shakes-an-iphone) look at Jeremy Ellison answer – syclonefx Oct 15 '11 at 22:43