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.
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.