2011-01-26 23 views
10

ぶれを検出私はこのような揺れのAPIを使用しています:客観C:

- (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event 
{ 
    if (event.subtype == UIEventSubtypeMotionShake) 
    { 
     [img stopAnimating];  
    } 
} 

I揺れが停止したことを検出するにはどうすればよいですか?あなたは正しい軌道に乗っている

答えて

22

は、しかし、あなたが揺れ検出するために、追加する必要がより多くのものが残っています:

あなたはmotionBeganまたはmotionEnded方法にNSLogを追加することでこれをテストし、シミュレータにすることができ、プレス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 
    } 
} 
+1

完璧!ありがとうございました... – itsame69

+0

canBecomeFirstResponderは理にかなっています。 –