diff --git a/MFJLabel.m b/MFJLabel.m index 8baef8e..9c6cc9e 100644 --- a/MFJLabel.m +++ b/MFJLabel.m @@ -292,16 +292,23 @@ - (void)longPress:(UILongPressGestureRecognizer *)sender NSUInteger glyphIndex = [layoutManager glyphIndexForPoint:location inTextContainer:textContainer]; NSUInteger characterIndex = [layoutManager characterIndexForGlyphAtIndex:glyphIndex]; - NSRange effectiveRange; - NSDictionary *attributes = [self.textStorage attributesAtIndex:characterIndex - effectiveRange:&effectiveRange]; - - self.linkRange = effectiveRange; - self.timer = [NSTimer scheduledTimerWithTimeInterval:0.75 - target:self - selector:@selector(timerFired:) - userInfo:attributes - repeats:NO]; + CGRect boundingRect = [layoutManager boundingRectForGlyphRange:NSMakeRange(glyphIndex, 1) + inTextContainer:textContainer]; + + if (CGRectContainsPoint(boundingRect, location)) + { + NSRange effectiveRange; + NSDictionary *attributes = [self.textStorage attributesAtIndex:characterIndex + effectiveRange:&effectiveRange]; + + self.linkRange = effectiveRange; + self.timer = [NSTimer scheduledTimerWithTimeInterval:0.75 + target:self + selector:@selector(timerFired:) + userInfo:attributes + repeats:NO]; + } + } else if ([sender state] == UIGestureRecognizerStateChanged) { @@ -373,6 +380,14 @@ - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceive NSUInteger glyphIndex = [layoutManager glyphIndexForPoint:location inTextContainer:textContainer]; NSUInteger characterIndex = [layoutManager characterIndexForGlyphAtIndex:glyphIndex]; + CGRect boundingRect = [layoutManager boundingRectForGlyphRange:NSMakeRange(glyphIndex, 1) + inTextContainer:textContainer]; + + if (CGRectContainsPoint(boundingRect, location) == NO) + { + return NO; + } + NSRange effectiveRange; NSDictionary *attributes = [self.textStorage attributesAtIndex:characterIndex effectiveRange:&effectiveRange];