Objective c 如何在UITextView上获取点击的坐标
我正在使用这个方法,但它只适用于我的UIView子类。如果我点击UITextView或UIButton或任何其他对象,它不会显示坐标。如何在UITextView上获取点击的坐标?为什么会这样Objective c 如何在UITextView上获取点击的坐标,objective-c,uitextview,coordinates,Objective C,Uitextview,Coordinates,我正在使用这个方法,但它只适用于我的UIView子类。如果我点击UITextView或UIButton或任何其他对象,它不会显示坐标。如何在UITextView上获取点击的坐标?为什么会这样 - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { UITouch *userTouch = [[event allTouches] anyObject]; CGPoint currentPos = [user
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *userTouch = [[event allTouches] anyObject];
CGPoint currentPos = [userTouch locationInView:self.view];
NSLog(@"Coordinates: (%f,%f)", currentPos.x, currentPos.y);
}
在ViewDidLoad方法中添加此代码
UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(singleTapRecognized:)];
singleTap.numberOfTapsRequired = 1;
[self.textView addGestureRecognizer:singleTap];
实现上述方法
-(void)singleTapRecognized:(id)sender{
CGPoint tapPoint = [sender locationInView:self.textView];
NSLog(@"Coordinates: (%f,%f)", tapPoint.x, tapPoint.y);
}
您可能需要对UITextView进行子类化,并应用此处找到的第二个答案:它可以工作,但不能识别单次快速单击(点击)。我需要按下鼠标按钮0.2-0.3秒,然后它就可以正常工作了。你知道为什么吗?延迟或其他什么?您正在使用滚动视图吗?有一个属性DelaysContentTouchs,您需要调整。是的,我正在使用。如何调整?将滚动视图延迟ContentTouches属性设置为NOI是否应将其添加到ViewController或UITextView?