且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

使用CGPoint跟踪longpressgesture的确切位置

更新时间:2023-11-07 14:14:04

该点始终出现在 UIScrollView的范围内,其中触发了 LongPressGestureRecognizer 。您应检查滚动视图的 contentOffset (对于水平布局使用 contentOffset.x ,并使用 contentOffset。 y 用于垂直布局)以检测应保存的图像。

The point will always appear within the bounds of the UIScrollView in which the LongPressGestureRecognizer is triggered. You should check your scroll view's contentOffset (use contentOffset.x for horizontal layouts and contentOffset.y for vertical layouts) to detect which image you should save.

此外,您可以将触摸点转换为 UIImageView 实例的本地坐标系,看看该点是否位于图像视图的边界 rect。

Additionally you could convert the touch point to the UIImageView instance's local coordinate system and see if the the point lies within the image view's bounds rect.

UPDATE

例如,您可以使用类似的东西来检测点是否在图像视图的边界内(注意:I让对此进行测试,这假设滚动视图中添加了多个图像视图):

For example you could use something like this to detect if the point is within the image view's bounds (note: I have not tested this and this is assuming there is more than one image view added to the scroll view):

if (CGRectContainsPoint(_imageView.bounds, [self.view convertPoint:location toView:_imageView]))
{
    // do something
}

您还应考虑检测应保存哪个图像并存储在向用户显示 UIActionSheet 之前引用该图像,因为它可能会减少您可能遇到的潜在问题的数量,以后会更容易阅读,但这是我的主观意见。

You should also consider detecting which image should be saved before and storing a reference to that image before displaying the UIActionSheet to the user as it may decrease the number of potential issues you might encounter and will be easier to read later, but this is my subjective opinion.