1
votes

I have a UIImageView which contains a scaled image. The image size is 3264 x 2448 and the UIImageView contentMode is set to AspectFit. The UIImageView's size is 320 x 427. I have the following view hierarchy:

WorkspaceView : UIView
   -> UIImageView (Contains the image)
   -> A UIView which contains a UITapGestureRecognizer

I am currently trying to get the coordinate from a touch based on the UIImageView (which has a large XY coordinate space - 2448). The UIView raises a touch based on its own view, not its superview. It has encapsulated the UITapGestureRecognizer so that it raises a delegate call.

How do I get the scaled XY touch point when given a coordinate inside of the UIView? I have tried the following code and it doesn't seem to work:

- (void)lineView:(LineView *)aLineView requestsDistanceForLine:(Line *)line {
   // aLineView is the subview
   // line contains the startpoint and endpoint of the aLineView - it's the model
   // capturedImageView is the local instance of the scaled UIImageView
   CGPoint startPoint =[self convertPoint:[line startPoint] toView:self.capturedImageView];
}

The startPoint ends up being too small. Any thoughts?

1

1 Answers

1
votes

It turns out someone has already solved this problem. Here's the link to the github repository for it.

https://github.com/nubbel/UIImageView-GeometryConversion