滚动时 UITextView 浮动蓝框 [英] UITextView floating blue box when scrolling

查看:25
本文介绍了滚动时 UITextView 浮动蓝框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个禁用滚动的 UITextView.它位于 UIScrollView 内.如果我输入fffs",则会出现一个*小蓝框.如果我在显示该框时滚动,该框不会消失,它只是 ** 漂浮在显示器上,看起来像是一个明显的错误.

I have a UITextView with scrolling disabled. It is inside a UIScrollView. If I type "fffs" a *little blue box appears. If I scroll while that box is displayed, the box doesn't disappear, it just **floats over the display and looks like an obvious bug.

如果我在启用滚动的情况下使用 UITextView,一旦 UITextView 开始滚动,该框就会隐藏.我假设 UITextView 钩住它自己的滚动条的滚动事件,当它有它们时,并在滚动时隐藏那个框.当它在其他一些 UIScrollView 中时不会发生这种情况,所以我可能需要自己做,但是我如何让它隐藏那个框(以及它通常所做的任何其他事情,例如应用自动更正) - 在一种健壮且非私有的 API 方式?

If I use UITextView with scrolling enabled, the box is hidden as soon as the UITextView starts to scroll. I assume UITextView hooks the scroll events of its own scrollbars, when it has them, and hides that box when it scrolls. This doesn't happen when it is inside some other UIScrollView, so I probably need to do that myself, but how do I get it to hide that box (and maybe anything else it normally does like apply the auto-correction) -- in a robust and non-private API way?

我可能会向 Apple 提交错误,但同时我希望有人能快速修复.

I might file a bug with Apple, but in the meantime I'm hoping someone has a quick fix.

*小蓝框 = 自动更正框/突出显示的东西——不知道该叫它什么,也许是我找不到任何现有答案的原因.

*little blue box = the auto-correct box/highlight thing -- not sure exactly what to call it, maybe why I couldn't find any existing answers.

**floats = think display:fixed in CSS

**floats = think display:fixed in CSS

更新:

我在 scrollViewWillBeginDragging 中尝试了这个和其他一些变体:

I tried this and some other variations of this, inside scrollViewWillBeginDragging:

UITextView *tv = GetFirstResponder(); // confirmed this returns correct value
tv.autocorrectionType = UITextAutocorrectionTypeNo;
[tv setNeedsDisplay];
[tv setNeedsLayout];
[tv setNeedsUpdateConstraints]; // just for giggles?

我确认代码正在运行,我什至没有费心添加代码来重新启用自动更正,所以我知道它没有被重新打开.我还可以确认它在某种程度上有效",因为当我单击另一个字段,然后返回到原始字段时,自动更正功能现在已禁用.

I confirmed the code is running, and I didn't even bother adding code to re-enable auto-correction yet, so I know it isn't being turned back on. I can also confirm it is "working" somewhat because when I click to another field, then back to the original field, auto-correct is now disabled.

我在想,如果我能找到那个小蓝框的 UIView,我可以隐藏/删除它.我尝试在 XCode 中使用新的 View Debugging,但它没有捕获蓝色框,所以它一定很特别.

I'm thinking if I could locate the UIView for that little blue box, I could hide/remove it. I tried using the new View Debugging in XCode, but it doesn't capture the blue box, so it must be special.

所有的人都以与我类似的方式使用 UITextView(在您键入时调整大小,没有内部滚动),我很惊讶还没有人弄清楚这一点.除非这是一个全新的错误,否则我使用的是最新的 iOS 版本和我的两个测试设备(iPod 5 和 iPad).

With all of the people using UITextView in a similar way that I am (resize as you type, no internal scrolling), I'm surprised nobody has figured this out yet. Unless it's a brand-new bug, I am using the latest iOS version and both of my test devices (iPod 5 and iPad).

推荐答案

到目前为止,这似乎有效,但我还没有进行大量测试:

This seems to work so far, but I haven't done a ton of testing yet:

-(void) walkViews:(UIView*)v
{
    NSString *className = NSStringFromClass([v class]);
    if([className isEqualToString:@"UIAutocorrectInlinePrompt"])
        v.hidden = YES;
    NSArray *subviews = v.subviews;
    for(UIView *sv in subviews)
        [self walkViews:sv];
}

-(void) scrollViewDidScroll:(UIScrollView *)scrollView
{
    NSArray *windows = [UIApplication sharedApplication].windows;
    for (UIWindow *w in windows)
    {
        [self walkViews:w];
    }
}

您可能希望为walkViews"取一个更好的名称,但基本上当 UIScrollView 滚动时,我会找到小蓝框"的视图并将其隐藏.到目前为止,我的有限测试,如果我再次开始打字并且需要它,盒子确实会回来.它似乎也没有弄乱任何其他自动更正功能.仍然是一个 hack,并且受制于那种类型的东西带来的所有问题,但在 Apple 修复这个错误之前,我可能会使用这个变通方法.

You'd probably want a better name for "walkViews", but basically when the UIScrollView scrolls, I locate the view for the "little blue box" and hide it. So far, my limited testing, the box does come back if I start typing again and it is needed. It doesn't seem to mess up any other auto-correct features either. Still a hack, and subject to all of the issues that comes with that type of thing, but until Apple can fix this bug, I'll probably use this work-around.

这篇关于滚动时 UITextView 浮动蓝框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆