Vous êtes sur la bonne voie, cependant, il y a encore plus de choses que vous devez ajouter à détecter secouer:
Vous pouvez tester cela en ajoutant un NSLog
aux motionBegan
ou motionEnded
méthodes, et dans le simulateur, appuyez sur CONTROL + COMMAND + Z
#pragma mark - Shake Functions
-(BOOL)canBecomeFirstResponder {
return YES;
}
-(void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:NO];
[self becomeFirstResponder];
}
-(void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:NO];
}
-(void)viewDidDisappear:(BOOL)animated {
[self resignFirstResponder];
[super viewDidDisappear:NO];
}
-(void)motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event
{
if (motion == UIEventSubtypeMotionShake)
{
// shaking has began.
}
}
-(void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event
{
if (motion == UIEventSubtypeMotionShake)
{
// shaking has ended
}
}
Parfait! Merci beaucoup ... – itsame69
canBecomeFirstResponder a du sens. –