PriyaJain PriyaJain - 3 months ago 12
Objective-C Question

Correct touch location after zooming and panning a pdf drawn in CATiledLayer on top of the UIScrollview in iOS

I am working on Atlas App in which I am displaying map which I can zoom and pan using pdf file. I am using vfr reader for this purpose and it is working fine. I want to detect the touch location so that I can get the correct state selected. I am getting the correct coordinate when view is not zoomed and panned using the code below:

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [touches anyObject];

CGPoint point = [touch locationInView:theScrollView];
}


But,when I zoom it out and pan it,the touch location changes and I am not getting the correct state selected. How will I get the correct selected state?

Answer

On debugging vfr reader classes I found that I can get the correct exact location of touch in ReaderContentPage class. This class gives the correct touch location after zooming also. You can get the point in processingSingleTap method as below:

- (id)processSingleTap:(UITapGestureRecognizer *)recognizer
{
    CGPoint point = [recognizer locationInView:self];
}

CGPoint point gives the correct touch location. And then use the delegate method to get the correct coordinates in the required class.