我正在检测将启动动画的震动,当它结束时,它会停止动画。有时它可以工作,但有时它没有意识到震动已经结束,所以它永远不会调用motionEnded 方法。有没有其他人有这个问题?解决方案?
-(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 (event.type == UIEventSubtypeMotionShake )
{
NSLog(@"1");
[img startAnimating];
}
}
-(void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event
{
if (event.type == UIEventSubtypeMotionShake )
{
NSLog(@"3");
[img stopAnimating];
}
}