-(void)didMoveToView:(SKView *)view
{
UITapGestureRecognizer* doubleTapGestureRecognizer = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(doubleTap:)];
doubleTapGestureRecognizer.numberOfTapsRequired = 2;
[self.view addGestureRecognizer:doubleTapGestureRecognizer];
}
-(void)doubleTap:(id)sender
{
NSLog(@"double tap");
}
我正在使用它向我的 SKView 添加手势识别器。它工作正常,当我双击时会调用双击,但是当我触摸屏幕并移动我的手指时,应用程序会因以下错误而崩溃:
[UITapRecognizer name]: unrecognized selector sent to instance 0x1756c600
为什么会这样?我没有在这个识别器上调用任何“名称”选择器。
我有这个方法:
#pragma mark - SKPhysicsContactDelegate
-(void)didBeginContact:(SKPhysicsContact *)contact
{
if(![contact.bodyA.node.name isEqualToString:@"player"])
{
[contact.bodyA.node performSelector:@selector(removeFromParent) withObject:nil afterDelay:1];
}
if(![contact.bodyB.node.name isEqualToString:@"player"])
{
[contact.bodyB.node performSelector:@selector(removeFromParent) withObject:nil afterDelay:1];
}
}
我注意到,如果我将其注释掉,则没有此类错误,但后来我将其替换为:
-(void)didBeginContact:(SKPhysicsContact *)contact
{
if(![contact.bodyA.node respondsToSelector:@selector(name)])
{
NSLog(@"%@ , %@ \n",contact.bodyA, contact.bodyA.node);
}
if(![contact.bodyB.node respondsToSelector:@selector(name)])
{
NSLog(@"%@ , %@",contact.bodyB, contact.bodyB.node);
}
}
并且调试日志中没有任何内容,只是同样的错误。到底是怎么回事?