我想开发一个应用程序。它可以检测用户是否触摸了特定的 view
,以便发生特定的操作。我实现了 SimpleOnGestureListener
来检测和监听用户在屏幕上的触摸。我现在的问题是,下面发布的方法给出了同一 View 的不同坐标,我不知道应该使用哪一个来与 SimpleOnGestureListener
给出的坐标进行比较。
给出 View 坐标的方法:
tv1.getLocalVisibleRect(tv1Rect);
tv1.getLocationOnScreen(tv1LocOnScreen);
tv1.setText("xCords: "+tv1.getX()+", yCords: "+tv1.getY());
最佳答案
要查明 View 是否包含您可以使用的触摸点
CGRectContainsPoint(your view frame, the CGPoint of the tap)
您可以通过以下方式从手势识别器中获取点击的 CGPoint
CGPoint location = [recognizer locationInView: view which the recognizer is attached to];
关于android - 哪个方法给出了 GestureDetector 给出的精确坐标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23941165/