realazy


How to detect double taps in UIWebView

You can use this robust approach, or this smart method. But the first is using the UNDOCUMENTED (private) API, and the second is not working for me (and for somebody according to the comments on that blog post). So this is my solution.

Subclass UIWebView and put these lines under your implementation:

- (UIView *)hitTest:(CGPoint)point
         withEvent:(UIEvent *)event
{
  CGPoint p = currentPoint;
  NSTimeInterval t = currentTimestamp;
  currentPoint = point;
  currentTimestamp = [event timestamp];

  if (CGPointEqualToPoint(p, point) &&
      [event timestamp] - t < 0.2){
    NSLog(@"double taps");
    return self.superview;
  }

  return [super hitTest:point withEvent:event];
}

Notice: declare ivar currentPoint and currentPoint in your header file.

It works like a charm.

2 Responses to “How to detect double taps in UIWebView”

  1. 筱白 Says:

    呃。。。。。英文不好的说,你应该全部翻译出来!:)

  2. lvyile Says:

    小僧cclv特来拜访
    rz

Leave a Reply


realazy (懒到死) is proudly powered by WordPress | Entries (RSS) and Comments (RSS)