Question

I'm implementing a custom UITextView (based on EGOTextView) using CoreText and conforming to the UITextInput protocol. I have almost everything working fine (phew!), except for one annoying thing. Autocorrect suggestion text is mirrored vertically and its highlight is slightly shifted to the right. Here's what it looks like:

Mirrored autocorrection

In the text field I typed "helo", which it autocorrects to "help." As you can see, the autocorrect text, but not its background, is vertically mirrored. Also, it's horiztontally offset to the right by ~7pt.

To address the second problem (the horizontal offset), I have verified that the firstRectForRange: method returns the correct CGRect. I've done this in two ways. The first was to visually check that when I display a UIMenuController it shows up in the right spot (it does). The second is to draw an outline around the CGRect returned by firstRectForRange:. Here's the same text with the CGRect outlined.

Outlined CGRect

As you can see, the correct area is outlined, but the autocorrect is marked/highlighted incorrectly.

I'm happy to share any code, but it's a huge class and I'm pretty stumped now. Any pointers would be massively appreciated!

Edit: The source code is available on the Experimental branch of this repository: github.com/cbrauchli/EGOTextView.

Was it helpful?

Solution

I aslo faced same same problem while trying your code and I found that there is no need to implement

- (UIView *)textInputView {
    return _textContentView;
}

See Apple documentation (This is typically an instance of the UITextInput-adopting class.) for more help on it. And if you want to keep implementation of this method, just return self from it, as here self (EGOTextView) is a instance of the UITextInput-adopting class.

I tried this at my end and works fine.

OTHER TIPS

@implementation EGOContentView

@synthesize delegate=_delegate;

- (id)initWithFrame:(CGRect)frame {...}

Add this:

- (void)addSubview:(UIView *)view
{
    if([view isKindOfClass:NSClassFromString(@"UIAutocorrectInlinePrompt")])
    {
        view.layer.geometryFlipped = !view.layer.geometryFlipped;
    }
    [super addSubview:view];
}

What I'm about to say it's just speculation. When the EGOTextView's layer's geometry is flipped it's fine without the above code but the text is upside down. So my guess it's that the system gets "confused" (could be a bug?) because it checks the EGOTextView's layer's geometry if it's flipped and adjusts the UIAutocorrectInlinePrompt's geometry based on that. But in fact EGOContentView's geometry is flipped not EGOTextView's and the UIAutocorrectInlinePrompt view is a subview of EGOContentView but since it's "adjusted" based on EGOContentView's superview's layer it ends up upside down.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top