- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我正在做一个测试项目,遇到了 UITextView 的问题。
我正在动态获取 TextView 中文本的内容大小,然后在需要时增加其高度。当高度达到我设置的阈值时,我将设置 scrollEnabled = YES 以启用滚动。奇怪的事情似乎发生了,如下面的屏幕截图所示:
在换行和启用滚动之前:
输入下一个字符后,将启用滚动:
之后,再次输入另一个字符, TextView 将再次恢复正常并启用滚动(实际上高度与之前的屏幕截图相同,我根据内容大小更改了高度,所以它变得与之前相同的高度启用滚动):
有人遇到过这个问题并能解决吗?如果这是一个 iOS7 错误,还有其他关于创建消息输入文本框的建议吗?我想知道以前的 iOS 版本是否有这个问题。
已编辑:
当textview的scrollEnabled为YES并更改textview.frame.size.height时,似乎会出现此问题,然后高度将重置为初始高度(如Interface Builder中设置的高度)。想知道这是否有助于解决这个问题。
下面显示了用于编辑 TextView 高度的代码(这是一个选择器的方法,将在收到 UITextViewTextDidChangeNotification 时调用):
NSInteger maxInputFieldWidth = self.inputTextField.frame.size.width;
CGSize maxSize = CGSizeMake(maxInputFieldWidth, 9999);
CGSize neededSize = [self.inputTextField sizeThatFits:maxSize];
NSInteger neededHeight = neededSize.height;
if (self.inputTextField.hasText)
{
[self.inputTextField scrollRangeToVisible:NSMakeRange([self.inputTextField.text length], 0)];
if (neededHeight <= TEXTVIEW_MAX_HEIGHT_IN_USE && neededHeight != previousHeight)
{
previousHeight = neededHeight;
CGRect inputTextFieldFrame = self.inputTextField.frame;
inputTextFieldFrame.size.height = neededHeight;
inputTextFieldFrame.origin.y = TEXTVIEW_ORIGIN_Y;
self.inputTextField.frame = inputTextFieldFrame;
}
else if (neededSize.height > TEXTVIEW_MAX_HEIGHT_IN_USE)
{
if (!self.inputTextField.scrollEnabled)
{
self.inputTextField.scrollEnabled = YES;
CGRect inputTextFieldFrame = self.inputTextField.frame;
inputTextFieldFrame.size.height = TEXTVIEW_MAX_HEIGHT_IN_USE;
inputTextFieldFrame.origin.y = TEXTVIEW_ORIGIN_Y;
self.inputTextField.frame = inputTextFieldFrame;
}
else if (neededHeight != previousHeight)
{
previousHeight = neededHeight;
CGRect inputTextFieldFrame = self.inputTextField.frame;
inputTextFieldFrame.size.height = TEXTVIEW_MAX_HEIGHT_IN_USE;
inputTextFieldFrame.origin.y = TEXTVIEW_ORIGIN_Y;
self.inputTextField.frame = inputTextFieldFrame;
}
}
}
最佳答案
一年多后,scrollEnabled 仍然会导致问题。我有一个类似的问题,设置 scrollEnabled = true
(我使用的是 Swift)不会导致任何更改。
我通过在 textView 的所有边上设置自动布局约束解决了这个问题。然后,就像你在这里详述的那样,我再次设置了 textView.frame
。我的猜测是这会导致一些内部更新,这实际上会打开滚动。我还猜测自动布局然后会强制 textView 保持在正确的高度,而不是您正在经历的崩溃。
关于iOS7 UITextView scrollEnabled=YES height,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22394658/
这个问题在这里已经有了答案: NSNumber Literals (5 个答案) 关闭 6 年前。 我正在发出一个 HTTP 请求,我必须在其中发送一个 bool 值。我试过他们两个。 两者的工作方
我使用 FireBug 测试了这两种情况,结果看起来非常相似: >>> var x = {"active": "yes"} >>> x.active "yes" >>> var x = {active
在 Objective-c 中,@YES/@NO 和 YES/NO 有什么区别?每种类型使用什么类型? 最佳答案 @YES 是 [NSNumber numberWithBool:YES] 的缩写形式
我正在编写一个脚本来创建虚拟机,显然我想支持标准的确认/whatif 语义。但是,如果我要创建多台机器,最好能区分"is"和“全部是”,这样我就不必重新确认每台机器。 $pscmdlet.Should
这个问题在这里已经有了答案: In JavaScript, why is "0" equal to false, but when tested by 'if' it is not false by
我需要编写一个正则表达式来验证字符串。如果正则表达式包含以下任何内容,则应传递字符串:y、Y、yes、YES , 1。这些字母可以是任何大小写。我是正则表达式和 JavaScript 的新手。 最佳答
我是网络开发的新手,如果能得到任何帮助,我将不胜感激。我有一个 HTML/CSS slider ,当 slider 处于"is"位置(如名字和主题)时,我想显示更多的文本框字段。如果可能的话,我真的希
bash: $: yes a [some output] then press Ctrl+Z $: yes b [some output] then press Ctrl+Z 然后,执行两
我感兴趣的是能够在 Yes/No 提示符下自动让我的 cmd 输入 Yes: __
以上说明了一切-我将 UITextField 设置为安全,但希望为用户提供使其不安全的选项(因此,如果他们在私有(private)区域中,他们可以确定输入的内容)。但是,假设他们误按了切换开关,并想将
当 ssh hostname 提示 The authenticity of host 'foobar' can't be established. ECDSA key fingerprint is .
如何在自定义 MKAnnotationView 上正确设置半径并允许标注?这会引发异常: 来 self 的自定义 MKAnnotationView 类: - (id)initWithFrame:(CG
如果我有 1200 行,并且我希望我的 120 行说"is"而其余的说“否”,我应该如何将其应用于 Excel 文件?我知道使用: =CHOOSE(RANDBETWEEN(1,2),"Yes","No
我想进行一个查询,返回如下所示的表结果: 列标题是我的一个表格中的字段,下面的数字是该字段的是/否条目数。 我遇到的问题是在行的开头显示是/否。我希望它以这种方式组织,以便更好地根据数据创建图表。 现
这个问题在这里已经有了答案: Literal @YES not working in iOS 5 / Xcode 4.4 (2 个答案) 关闭 7 年前。 使用 XCode 4.4 的 Conver
这段代码: $query = array( "var" => "no", "not_var" => "yes", "var2" => "maybe" ); print http
在我的 Dynamics CRM 机会表单中,我添加了销售配额分配网格。如果在整个网格中输入了四个以上"is",我希望显示一条警告消息(或类似的内容)。例如,假设记录“A”t 有 4 个标记为"is"
This question already has answers here: How do I perform an IF…THEN in an SQL SELECT? (31个答案) 已关闭6年。
考虑以下文档: foo: bar: Yes 根据the spec,这应该解释为Boolean,而不是String。 但是,it seems对此文档产生了相同的解释: foo: bar: 'Ye
在网页的第一页上,它要求用户从下拉列表中选择他们想要的产品类型,并且为每个产品指定一个值 0,1,2...然后,一旦他们继续,他们就会被发送到不同的网页,并根据他们选择的产品在那里我希望单选按钮自动选
我是一名优秀的程序员,十分优秀!