- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我想弄清楚为什么在使用 locationOfTouch:inView 时出现错误。最终,我仅使用 locationOfTouch 调用创建了一个新 View ,并且每当我触摸该 View 时,我仍然会收到 SIGABRT。
除了 import 语句,以下是我认为的所有代码:
@interface Dummy : UIView <UIGestureRecognizerDelegate> {
UIPanGestureRecognizer *repositionRecognizer;
}
@end
这是实现:
@implementation Dummy
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
repositionRecognizer = [[UIPanGestureRecognizer alloc]
initWithTarget:self
action:@selector(reposition:)];
[repositionRecognizer setDelegate:self];
[self addGestureRecognizer:repositionRecognizer];
self.backgroundColor = [UIColor grayColor];
}
return self;
}
- (void)reposition:(UIGestureRecognizer *) gestureRecognizer {
[gestureRecognizer locationOfTouch:0 inView:self];
//[gestureRecognizer locationInView:self];
}
@end
如果我使用 locationInView,它工作正常。如果我使用 locationOfTouch:inView,程序会在触摸结束后立即中止。
编辑:在控制台上,对于此类,不会显示任何错误消息。 IDE 使用 SIGABRT 指向 main.m。单击“继续”会导致“EXC_BAD_INSTRUCTION”。屏幕截图可在 http://imageshack.us/photo/my-images/849/consolel.png/ 上找到
最佳答案
这会崩溃,因为它假定存在零接触。您需要先确认有一个,如下所示:
- (void)reposition:(UIGestureRecognizer *) gestureRecognizer {
if (gestureRecognizer.numberOfTouches > 0){
CGPoint point = [gestureRecognizer locationOfTouch:0 inView:self];
NSLog(@"%@",NSStringFromCGPoint(point));
}
}
如果触摸数组为空(当您抬起手指或将其移离屏幕)则没有 touchAtIndex:0
。
关于ios - locationOfTouch 导致 SIGABRT,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8456952/
嘿,我一直在尝试获取用户滑动的位置,以便我可以在屏幕上显示 3 个可滑动的区域,并根据滑动的 y 坐标确定他们对哪个部分使用react。 这是代码 CGPoint touchPoint = [reco
我想弄清楚为什么在使用 locationOfTouch:inView 时出现错误。最终,我仅使用 locationOfTouch 调用创建了一个新 View ,并且每当我触摸该 View 时,我仍然会
嗨我有这个识别器,设置了 2 个触摸,但它只返回一个,而不是两个 CGPoint -(void)gestureLoad { UIGestureRecognizer *recognizer; recog
我是一名优秀的程序员,十分优秀!