1

I'm using Text Kit to render some rich text on a text view.

My problem is there seems to be a bug in iOS 7 for caret placement. Whenever you long press on a blank area in a text view the caret seems to disappear and no pop over menu with (Cut, Copy, Select, etc) is presented.

You can understand the issue better via taking a look at this short video: http://cl.ly/1E0s2A2S0t2t

You can try it out yourself by downloading the IntroToTextKit sample code from Apple. Here's a link to the project: http://cl.ly/0h0T0V1Z0D3H

Any workarounds to this would be really appreciated.

Tanmay
  • 46
  • 5

1 Answers1

1

Found a solution.

Subclass UITextView and add the following:

    - (UITextPosition *)closestPositionToPoint:(CGPoint)point
{
    point.y -= self.textContainerInset.top;
    point.x -= self.textContainerInset.left;

    CGFloat fraction = 1;
    NSUInteger glyphIndex = [self.layoutManager glyphIndexForPoint:point inTextContainer:self.textContainer fractionOfDistanceThroughGlyph:&fraction];    

    NSInteger index = glyphIndex;
    if (![[self.text substringFromIndex:self.text.length - 1] isEqualToString:@"\n"]) {
        if (index == [self.text length] - 1 && roundf(fraction) > 0) {
            index++;
        }
    }

    NSUInteger characterIndex = [self.layoutManager characterIndexForGlyphAtIndex:index];
    UITextPosition *pos = [self positionFromPosition:self.beginningOfDocument offset:characterIndex];
    return pos;
}
Tanmay
  • 46
  • 5