views:

88

answers:

1

Hi,

I am displaying a pub or a pdf file in webview.But i am not able to detect the touch on the webview.

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event 

above method is called when i touch any text of the pdf or pub file.How can i detect the click on the webview which is displaying a pdf or a pub file.Please help me out.Thanks.

EDIT:

This is my Code:

- (void)viewDidLoad {
[super viewDidLoad];
NSURL *url = [NSURL URLWithString:@"http://dblog.com.au"];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[webView loadRequest:request];
UILongPressGestureRecognizer *longPressGestureRecognizer = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(handleLongPress:)];
longPressGestureRecognizer.minimumPressDuration = 6.0;
[self.webView addGestureRecognizer:longPressGestureRecognizer];
[longPressGestureRecognizer release];

}

- (void)handleLongPress:(UIGestureRecognizer *)gestureRecognizer {
NSLog(@"Long press detected");
 }

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
return YES;
}

Please check it ,did i make any mistake?

+1  A: 

Try something like:

UILongPressGestureRecognizer *longPressGestureRecognizer = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(handleLongPress:)];
longPressGestureRecognizer.minimumPressDuration = 10.0;
[self.webView addGestureRecognizer:longPressGestureRecognizer];
[longPressGestureRecognizer release];

And then:

- (void)handleLongPress:(UIGestureRecognizer *)gestureRecognizer {
    NSLog(@"Long press detected");
}

EDIT:

Add this:

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
return YES;
}

But pressing same place for 10 seconds is a really long time... the default value for a long press is 0.4 seconds. Keep in mind that if the finger is dragged it is no longer a long press..

Larsaronen
@Larsaronen : Sorry its not working....
Warrior
Try adding the new method in my edited post!
Larsaronen
@Larsaronen : I have edited my question and posted my code .please review it...
Warrior
@Larsaronen: Thanks it worked fine....
Warrior
@Larsaronen : is there any way for me to to determine the coordinates at the point touched?
Warrior
Yes there is CGPoint tapLocation = [gestureRecognizer locationInView:self.webView];
Larsaronen
@Larsaronen : Thanks i was able to determine it.
Warrior