2009-10-10 9 views
-1

J'ai un ViewController qui fonctionne parfaitement avec un bouton qui déclenche une action. Je voudrais remplacer le bouton avec un événement tremblement donc je l'ai googlé autour et créé une classe de ShakeDetector qui ineherits de UIViewShake Detection iPhone 3.0 ne fonctionne pas

et ma mise en œuvre est la suivante:

@implementation ShakeDetector 

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

    - (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event 
    { 
     if (motion == UIEventSubtypeMotionShake) 
     { 
      // User was shaking the device. Post a notification named "shake". 
      //[[NSNotificationCenter defaultCenter] postNotificationName:@"spin" object:self]; 
      NSLog(@"sss"); 
     } 
    } 

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

@end 

Mais je ne peux pas le faire fonctionner ... toute aide?

Merci

Répondre

1

Put:

-(BOOL)canBecomeFirstResponder 
{ 
    return YES; 
} 

et pour votre point de vue:

- (void)viewDidAppear:(BOOL)animated { 
    [super viewDidAppear:animated]; 
    [self becomeFirstResponder]; 
} 
- (void)viewDidDisappear:(BOOL)animated { 
    [self resignFirstResponder]; 
    [super viewDidDisappear:animated]; 
} 

Vous pouvez également écrire dans viewWillAppear et viewWillDisappear

Questions connexes