Use UIEdgeInset to extend tap area

This commit is contained in:
choefele
2014-04-15 11:41:38 +02:00
parent edc9be625d
commit d90179a199
3 changed files with 6 additions and 11 deletions

View File

@@ -111,7 +111,7 @@
NSMutableAttributedString *attributedText = [self.linkTextView.attributedText mutableCopy];
[attributedText addAttribute:CCHLinkAttributeName value:@"http://google.de" range:linkRange];
self.linkTextView.attributedText = attributedText;
self.linkTextView.extendedTapAreaX = 50;
self.linkTextView.tapAreaInsets = UIEdgeInsetsMake(0, 0, 0, -50);
__block NSUInteger blockCalled = 0;
[self.linkTextView enumerateLinkRangesContainingLocation:CGPointMake(100, 20) usingBlock:^(NSRange range) {
@@ -127,7 +127,7 @@
NSMutableAttributedString *attributedText = [self.linkTextView.attributedText mutableCopy];
[attributedText addAttribute:CCHLinkAttributeName value:@"http://google.de" range:linkRange];
self.linkTextView.attributedText = attributedText;
self.linkTextView.extendedTapAreaY = 80;
self.linkTextView.tapAreaInsets = UIEdgeInsetsMake(0, 0, -80, 0);
__block NSUInteger blockCalled = 0;
[self.linkTextView enumerateLinkRangesContainingLocation:CGPointMake(50, 100) usingBlock:^(NSRange range) {

View File

@@ -47,10 +47,8 @@ extern NSString *const CCHLinkAttributeName;
/** The maximum movement of the fingers on the link before the gesture is ignored (default = 10 points). */
@property (nonatomic, assign) CGFloat allowableMovement;
/** Additional tap area left and right of the link text (default: 10 points). */
@property (nonatomic, assign) CGFloat extendedTapAreaX;
/** Additional tap area above and below of the link text (default: 10 points). */
@property (nonatomic, assign) CGFloat extendedTapAreaY;
/** Expands or shrinks the tap area of the link text (default: {-5, -5, -5, -5}). */
@property (nonatomic, assign) UIEdgeInsets tapAreaInsets;
/** The gesture recognizer used to detect links in this text view. */
@property (nonatomic, strong, readonly) CCHLinkGestureRecognizer *linkGestureRecognizer;

View File

@@ -65,8 +65,7 @@ NSString *const CCHLinkAttributeName = @"CCHLinkAttributeName";
self.linkGestureRecognizer.delegate = self;
[self addGestureRecognizer:self.linkGestureRecognizer];
self.extendedTapAreaX = 10;
self.extendedTapAreaY = 10;
self.tapAreaInsets = UIEdgeInsetsMake(-5, -5, -5, -5);
}
- (id)debugQuickLookObject
@@ -85,7 +84,6 @@ NSString *const CCHLinkAttributeName = @"CCHLinkAttributeName";
[attributedString enumerateAttribute:CCHLinkAttributeName inRange:NSMakeRange(0, attributedString.length) options:0 usingBlock:^(id value, NSRange range, BOOL *stop) {
if (value) {
[self enumerateViewRectsForRanges:@[[NSValue valueWithRange:range]] usingBlock:^(CGRect rect, NSRange range, BOOL *stop) {
rect = CGRectInset(rect, -self.extendedTapAreaX, -self.extendedTapAreaY);
CGContextFillRect(context, rect);
}];
}
@@ -129,6 +127,7 @@ NSString *const CCHLinkAttributeName = @"CCHLinkAttributeName";
[self.layoutManager enumerateEnclosingRectsForGlyphRange:glyphRange withinSelectedGlyphRange:NSMakeRange(NSNotFound, 0) inTextContainer:self.textContainer usingBlock:^(CGRect rect, BOOL *stop) {
rect.origin.x += self.textContainerInset.left;
rect.origin.y += self.textContainerInset.top;
rect = UIEdgeInsetsInsetRect(rect, self.tapAreaInsets);
block(rect, range, stop);
}];
@@ -143,8 +142,6 @@ NSString *const CCHLinkAttributeName = @"CCHLinkAttributeName";
[attributedString enumerateAttribute:CCHLinkAttributeName inRange:NSMakeRange(0, attributedString.length) options:0 usingBlock:^(id value, NSRange range, BOOL *stop) {
if (value) {
[self enumerateViewRectsForRanges:@[[NSValue valueWithRange:range]] usingBlock:^(CGRect rect, NSRange range, BOOL *stop) {
rect = CGRectInset(rect, -self.extendedTapAreaX, -self.extendedTapAreaY);
if (CGRectContainsPoint(rect, location)) {
found = YES;
*stop = YES;