次のようなシェイク API を使用しています。
- (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event
{
if (event.subtype == UIEventSubtypeMotionShake)
{
[img stopAnimating];
}
}
揺れが止まったことをどのように検出しますか?
次のようなシェイク API を使用しています。
- (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event
{
if (event.subtype == UIEventSubtypeMotionShake)
{
[img stopAnimating];
}
}
揺れが止まったことをどのように検出しますか?
あなたは正しい方向に進んでいますが、揺れを検出するために追加する必要があるものがまだまだあります。
またはメソッドにを追加してこれをテストできますNSLog
。シミュレータで、を押します。motionBegan
motionEnded
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
}
}