好的,我在这里遇到了一个非常奇怪(对我来说)的问题。我的视图中有一个150x150的按钮,我已经给该按钮添加了一个UILongPressGestureRecognizer
,因为我需要在按钮按下时获取按钮被按下的位置。我用以下代码实现:
-(CGPoint)detectedTouch:(UILongPressGestureRecognizer *)sender {
CGPoint touchPoint = [sender locationInView:button];
return touchPoint;
}
-(void)myAction {
CGPoint touchPoint = [self detectedTouch:myGestureRecognizer];
NSLog(@"touchPoint = %f, %f", touchPoint.x, touchPoint.y);
//do stuff
}
当按钮在普通视图上时,一切都正常工作。但是当按钮在scrollView上时,只有当您按下它约一秒钟时才能正常工作。如果您释放得太快,日志将给出以下信息:
touchPoint = nan, nan
任何帮助解决这个问题的意见都将不胜感激!