Frage

That's my code.

-(void)motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event
{
    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(shake) name:@"shake" object:nil];
    if(event.type == UIEventTypeMotion && event.subtype == UIEventSubtypeMotionShake)
    {

       // SOMETHING HERE
    }
            NSLog(@"motion Began");
    }
     else
    {
        NSLog(@"Shake Is Over");
    }
}

I want to shake/motion on my device.I used that code but it is not working..

War es hilfreich?

Lösung

write down below code...then check

-(BOOL) canBecomeFirstResponder {

return YES;

}

-(void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event 
{
   //your stuff

}

-(void)viewDidAppear:(BOOL)animated {

[self becomeFirstResponder];

}

-(void)viewDidDisappear:(BOOL)animated {

[self resignFirstResponder];

}

let me know it is working or not!!!

Happy Coding!!!!

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top