I have simple UIWebView
with loaded html file. I want to show the PopOverController
pointed to the selected text like -
.
I want the coordinates
of selected text from UIWebView
.
If I set the scalesPageToFit
property of UIWebView
to NO
, then this link works fine. If I set the scalesPageToFit
property of UIWebView
to YES
, then it fails.
Anyone please help me to sort out my problem.
First of all remove the native long press gesture recogniser like this:
for(UIGestureRecognizer *gesRecog in yourWebView.gestureRecognizers)
{
if([gesRecog isKindOfClass:[UILongPressGestureRecognizer class]])
{
[startTF removeGestureRecognizer:gesRecog];
}
}
Then assign a custom one:
UILongPressGestureRecognizer *myOwnLongPressRecog = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(handleWebViewLongpress:)];
// set numberOfTapsRequired and numberOfTouchesRequired as per your requirement:
[yourWebView addGestureRecognizer:myOwnLongPressRecog];
// Handle Long press like this:
- (void) handleWebViewLongpress: (UIGestureRecognizer *) recog
{
int zoomedWidth = [[yourWebView stringByEvaluatingJavaScriptFromString:@"window.innerWidth"] intValue];
CGFloat scale = yourWebView.frame.size.width / zoomedWidth; // get the scaled value of your web view
CGPoint zoomedCords = [gesture locationInView:self.webView];
zoomedCords.x /= scale; // Normal math. Divide by the scale to get the real thing.
zoomedCords.y /= scale;
NSLog(@"%@", zoomedCords);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With