- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我需要在渲染之前捕获键入的文本,以便对其应用一些属性。
为此,我使用了 UITextView 的委托(delegate)方法 shouldChangeTextInRange 以及 NSAttributedString。到目前为止一切顺利,而且有效。
问题是,当 UITextView 获得一定数量的文本并开始滚动时,更改 attributedText 使其滚动到顶部,而下一个字符将使它滚动回到末尾。
它在打字时继续上下移动..
设置textview.text,而不是属性文本,n
有什么建议吗?
提前致谢。
- (BOOL) textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
{
NSAttributedString * newString = [[NSAttributedString alloc] initWithString:text attributes:nil];
NSMutableAttributedString * string = [[NSMutableAttributedString alloc] initWithAttributedString:_textView.attributedText];
[string insertAttributedString:newString atIndex:range.location];
textView.attributedText = string;
range.location += text.length;
textView.selectedRange = range;
return NO;
}
最佳答案
我不确定你的 shouldChangeTextInRange
的意义,但要修复不需要的自动滚动,请尝试使用 包围
.textView.attributedText
的设置[textView setScrollEnabled:NO]
即:
[textView setScrollEnabled:NO];
textView.attributedText = string;
range.location += text.length;
[textView setScrollEnabled:YES];
关于ios - 带有 attributedText 的 UITextField shouldChangeTextInRange 导致滚动奇怪的行为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14593125/
我有一个UITextField我想使用正则表达式。我想使用 - (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRan
我有一个 UITextView,它有一个包含 4 个字符的空白字符串作为缩进的前缀。如果我输入大量文本然后按住退格键大约一秒钟,它会逐字逐句快速删除文本,但它也会删除我的“分隔符空格”,这会导致我的
iOS8 的预测输入多次调用 UITextView 的以下委托(delegate)方法,导致所选单词被多次插入到 View 中。 此代码适用于键入单个字母和复制/粘贴,但在使用预测输入栏时无效;为什么
我有以下 UISearchBar 委托(delegate)方法,它自己工作(它在单独时被调用)。 -(void)searchBarSearchButtonClicked:(UISearchBar *)
我使用自定义 UITextView,需要在返回点击时隐藏键盘。我需要捕获'ShouldChangeTextInRange'什么有textview,我不知道为什么但是 方法未被调用。这是我的 TextV
我在最新的 iOS 版本中看到 UITextView 的一个奇怪问题。根据我目前的理解,它仅发生在 iOS 13 中。我的一位用户在 iOS 12.4.1 上报告了此问题,但我无法在任何 iOS 13
我遇到了以下问题,不确定这是 iOS 错误,还是我误解了 UITextViewDelegate 回调。我能够在我的设备(iPad 视网膜)和模拟器上重现此行为仅当我使用软件键盘(即使用我的鼠标单击屏幕
我是 Swift 的新手,我有很多 RND,但我无法获得成功。我有用范围替换字符串我正在使用这段代码但是它的返回错误我正在使用 swift 2.0 let aString: String = txt_
这是我到目前为止所得到的。不确定为什么不调用此方法。 // viewDidLoad -> // textView?.delegate = self func textView(textView: UI
我想知道如何使用 shouldChangeTextInRange 创建 Firebase matchesRegex 查询 和列出当前结果。 我之前在 Parse 中做过,用于在 Parse Cloud
我想知道下面代码的工作原理。 - (BOOL) textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)ra
我需要在渲染之前捕获键入的文本,以便对其应用一些属性。 为此,我使用了 UITextView 的委托(delegate)方法 shouldChangeTextInRange 以及 NSAttribut
当使用外部键盘时,我的 UITextView 会在我按下 Backspace 键(“向后删除”)时触发 shouldChangeTextInRange 消息,但如果我按下 Delete ( "forw
我正在使用这段代码来设置我 View 中的 uitextview 的参数。 _textview=[[UITextView alloc]init]; [_textview setUserInteract
我使用 (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NS
我的一个项目中有一个相当复杂的 NSTextView 子类。我目前正在努力让查找/替换与内联查找栏(例如 Safari、Xcode)一起工作,并希望正确支持替换操作的撤消/重做。 我希望“全部替换”命
我正在尝试为 UITextView 实现字符计数器,但发现计数器在以下情况下不准确: 输入几个文本字符,例如“The” 点击返回 25 次 按住删除按钮删除文本(并按住直到光标到达顶部) 当光标到达顶
我有一个 UITextView,我正在将所有 TextView 更改事件记录到一个数组中。 当用户快速删除时(按住delete键一次删除一个单词而不是一个字符),当调用textView:shouldC
我是一名优秀的程序员,十分优秀!