Tracing the exact location of the longpressgesture with CGPoint

前端 未结 1 1133
长情又很酷
长情又很酷 2021-01-24 12:38

By using CGPoint location it is always saving the last image in uiscrollview. When i m tapping on other image to save. What can i do to save the exact image one i tapped.

相关标签:
1条回答
  • 2021-01-24 13:11

    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.

    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

    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
    }
    

    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.

    0 讨论(0)
提交回复
热议问题