UITapGestureRecognizer导致应用程序在滑动后崩溃。在很短的距离上完成刷卡不会引起任何问题,但是在更长的距离上进行刷卡会产生错误:
-[UITapRecognizer name]: unrecognized selector sent to instance 0x17ee27c0
其中0x17ee27c0是随机值。
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UITapRecognizer name]: unrecognized selector sent to instance 0x17ee27c0'
*** First throw call stack:
(0x2cb7dc1f 0x3a328c8b 0x2cb83039 0x2cb80f57 0x2cab2df8 0x2feee1c1 0x2d7d01cf 0x3024822d 0x300671ad 0x30066bcd 0x3003d3dd 0x302b0c29 0x3003be39 0x2cb44377 0x2cb43787 0x2cb41ded 0x2ca90211 0x2ca90023 0x33e890a9 0x3009c1d1 0xdca87 0x3a8a8aaf)
libc++abi.dylib: terminating with uncaught exception of type NSException
UITapRecognizer *(0x17ee27c0)来自tapGestureRecognizer._imp
这在运行iOS 8.1的多个设备上发生。源代码是在Xcode 6上编译的。
这是我声明UITapGestureRecognizer的方式:
UITapGestureRecognizer *tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(viewTapped:)];
[myView addGestureRecognizer:tapGestureRecognizer];
这是方法:
- (void)viewTapped:(UITapGestureRecognizer *)sender { }
UITapGestureRecognizer放置在SKView上;
您正在尝试在name
实例上运行一个名为UITapGestureRecognizer
的选择器,但是UITapGestureRecognizer
没有这样的选择器,这就是您的程序崩溃的原因。检查要在哪里调用name
(可能在viewTapped
内部),并确保将其应用于正确的对象。
我在一个SpriteKit游戏中遇到了相同的问题,这是由于您在场景之间的过渡期间使用手势引起的,我通过在过渡之前将gestureRecognizer.enable
属性(documentation)设置为NO
来解决了此问题。
您确定ViewTapped:
正在等待一个参数。
您可以使用强制转换为例:action as MyTapGesture