Преглед изворни кода

fix the text rect query issue in YYLabel #150

ibireme пре 9 година
родитељ
комит
3bb85d5ae9
1 измењених фајлова са 8 додато и 2 уклоњено
  1. 8 2
      YYText/YYLabel.m

+ 8 - 2
YYText/YYLabel.m

@@ -127,7 +127,10 @@ static dispatch_queue_t YYLabelGetReleaseQueue() {
     if (_highlight) {
         YYTextAction longPressAction = _highlight.longPressAction ? _highlight.longPressAction : _highlightLongPressAction;
         if (longPressAction) {
-            CGRect rect = [_innerLayout rectForRange:[YYTextRange rangeWithRange:_highlightRange]];
+            YYTextPosition *start = [YYTextPosition positionWithOffset:_highlightRange.location];
+            YYTextPosition *end = [YYTextPosition positionWithOffset:_highlightRange.location + _highlightRange.length affinity:YYTextAffinityBackward];
+            YYTextRange *range = [YYTextRange rangeWithStart:start end:end];
+            CGRect rect = [_innerLayout rectForRange:range];
             rect = [self _convertRectFromLayout:rect];
             longPressAction(self, _innerText, _highlightRange, rect);
             [self _removeHighlightAnimated:YES];
@@ -508,7 +511,10 @@ static dispatch_queue_t YYLabelGetReleaseQueue() {
         if (!_state.touchMoved || [self _getHighlightAtPoint:point range:NULL] == _highlight) {
             YYTextAction tapAction = _highlight.tapAction ? _highlight.tapAction : _highlightTapAction;
             if (tapAction) {
-                CGRect rect = [_innerLayout rectForRange:[YYTextRange rangeWithRange:_highlightRange]];
+                YYTextPosition *start = [YYTextPosition positionWithOffset:_highlightRange.location];
+                YYTextPosition *end = [YYTextPosition positionWithOffset:_highlightRange.location + _highlightRange.length affinity:YYTextAffinityBackward];
+                YYTextRange *range = [YYTextRange rangeWithStart:start end:end];
+                CGRect rect = [_innerLayout rectForRange:range];
                 rect = [self _convertRectFromLayout:rect];
                 tapAction(self, _innerText, _highlightRange, rect);
             }