- r - 以节省内存的方式增长 data.frame
- ruby-on-rails - ruby/ruby on rails 内存泄漏检测
- android - 无法解析导入android.support.v7.app
- UNIX 域套接字与共享内存(映射文件)
我有一个在 iOS 8 下运行的 UITableView
,我在 Storyboard中使用来自约束的自动单元格高度。
我的一个单元格包含一个 UITextView
,我需要它根据用户输入收缩和扩展 - 点击以收缩/扩展文本。
我通过向 TextView 添加运行时约束并更改约束上的常量以响应用户事件来执行此操作:
-(void)collapse:(BOOL)collapse; {
_collapsed = collapse;
if(collapse)
[_collapsedtextHeightConstraint setConstant: kCollapsedHeight]; // 70.0
else
[_collapsedtextHeightConstraint setConstant: [self idealCellHeightToShowFullText]];
[self setNeedsUpdateConstraints];
}
每当我这样做时,我都会将其包装在 tableView
更新中并调用 [tableView setNeedsUpdateConstraints]
:
[tableView beginUpdates];
[_briefCell collapse:!_showFullBriefText];
[tableView setNeedsUpdateConstraints];
// I have also tried
// [self.tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationTop];
// with exactly the same results.
[tableView endUpdates];
当我执行此操作时,我的单元格会展开(并在执行此操作时进行动画处理)但我收到约束警告:
2014-07-31 13:29:51.792 OneFlatEarth[5505:730175] Unable to simultaneously satisfy constraints.
Probably at least one of the constraints in the following list is one you don't want. Try this: (1) look at each constraint and try to figure out which you don't expect; (2) find the code that added the unwanted constraint or constraints and fix it. (Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints)
(
"<NSLayoutConstraint:0x7f94dced2b60 V:[UITextView:0x7f94d9b2b200'Brief text: Lorem Ipsum i...'(388)]>",
"<NSLayoutConstraint:0x7f94dced2260 V:[UITextView:0x7f94d9b2b200'Brief text: Lorem Ipsum i...']-(15)-| (Names: '|':UITableViewCellContentView:0x7f94de5773a0 )>",
"<NSLayoutConstraint:0x7f94dced2350 V:|-(6)-[UITextView:0x7f94d9b2b200'Brief text: Lorem Ipsum i...'] (Names: '|':UITableViewCellContentView:0x7f94de5773a0 )>",
"<NSLayoutConstraint:0x7f94dced6480 'UIView-Encapsulated-Layout-Height' V:[UITableViewCellContentView:0x7f94de5773a0(91)]>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x7f94dced2b60 V:[UITextView:0x7f94d9b2b200'Brief text: Lorem Ipsum i...'(388)]>
388 是我计算出的高度,UITextView
上的其他约束来自 Xcode/IB。
最后一个困扰我 - 我猜 UIView-Encapsulated-Layout-Height
是单元格首次呈现时的计算高度 - (我设置了我的 UITextView
height >= 70.0) 然而,这个派生约束随后否决了更新的用户 cnstraint 似乎并不正确。
更糟糕的是,虽然布局代码说它试图打破我的高度限制,但它并没有 - 它继续重新计算单元格高度并且一切都按照我的意愿绘制。
那么,什么是 NSLayoutConstraint
UIView-Encapsulated-Layout-Height
(我猜这是自动调整单元格大小的计算高度),我应该怎么做强制它干净地重新计算?
最佳答案
尝试将 _collapsedtextHeightConstraint
的优先级降低到 999。这样系统提供的 UIView-Encapsulated-Layout-Height
约束始终优先。
它基于您在 -tableView:heightForRowAtIndexPath:
中返回的内容。确保返回正确的值,并且您自己的约束和生成的约束应该相同。您自己的约束的较低优先级只是暂时需要,以防止在折叠/展开动画运行时发生冲突。
补充:虽然系统提供的约束是否正确可能值得商榷,但与框架抗争是没有意义的。简单地接受系统约束优先。如果您认为系统约束有误,请确保从委托(delegate)返回正确的 rowHeight。
关于ios - 什么是 NSLayoutConstraint "UIView-Encapsulated-Layout-Height"以及我应该如何强制它干净地重新计算?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25059443/
这个问题在这里已经有了答案: How can I vertically align elements in a div? (28 个答案) Vertical Aligned Text and Im
我想做一个像 view0.height = view1.height + view2.height 这样的约束。当 view1.height 或 view2.height 改变时,view0.heig
有人可以解释为什么这个标记: 呈现大约 2x18 的 float div(在 Chrome/Firefox 中)而不是 2x2 div? 即使所有空格都被删除,图像似乎也遵循 font-
我的 HTML 页面上有一些可拉伸(stretch)的元素。 使用这个 CSS .stretchable-element { height: 25%; } 随着浏览器窗口高度的增加,可伸缩元素
我在“developer.android.com”上查看以缩小我的位图文件,但我发现了一件事我不明白。所以我很感激你能给我一点帮助。 这是一个 snippet来自 developer.android.
假设我们有以下设置: .container { background-color: red; width: 500px; min-height: 300px; } .child { b
我遇到了高度错误的问题 $(window).height(); 也有类似的问题 here 就我而言,当我尝试时 $(document).height(); 它似乎返回了正确的结果 窗口高度返回320
我正在尝试使用 javaFX (2.2) 开发桌面应用程序,但我遇到了一些困难,无法真正让它按照我希望的方式运行。作为该框架的新用户,我可能没有按应有的方式使用它... 我想要的是一种仪表板,在 Sc
就这么简单:) 我右边的列动态变化,由于左列的高度设置为 100%,我认为根据 Right_Column 的高度动态修改容器的高度会很好。有小费吗?谢谢:) 最佳答案 如果我正确理解了问题,你可以做这
我有一个 ScrollView(包含 NSTextEditor),其顶部、左侧和右侧约束相对于其容器(主窗口)正确设置为 0。 我无法使其高度为主容器的一半。有什么帮助吗? 最佳答案 如果我理解正确,
这个问题之前曾被问过(Infinite Scroll on Mobile browsers),但没有得到回应。 我正在尝试实现无限滚动。 检查文档是否在底部,导致更多加载的函数是: if ($(win
这个问题在这里已经有了答案: height:100% VS min-height:100% (4 个答案) 关闭 6 年前。
我在尝试解决这个问题时遇到了一些问题。我已经编写了一个 jquery 函数来检测用户何时点击页面底部并触发一个函数。现在,虽然这适用于最常见的屏幕尺寸,但当用户的屏幕太大以至于可以一次看到整个页面时,
如何获得与导航高度(填充)相同的导航高度 ...!? nav { width: 100%; } nav ul { text-align: center; background-
所以,实际上我可能完全想多了,应该放弃最小高度,但我目前有以下 HTML:
我正在阅读 Bootsrap3 文档。我发现这段页脚代码粘在屏幕底部。 html, body { height: 100%; } #wrap { min-height: 100%; height: a
我对容器 div 的高度有疑问。我想 它是 body 的 100%,但不起作用。我添加了 css body height=100% var d = document; $(d).ready(funct
我有一个三部分布局:页眉、内容和页脚。我非常熟悉绝对定位技术;当我希望内容 div 扩展到可用高度的 100% 时,我经常使用它。 在这种情况下,我的问题是我事先不知道页脚的高度,它是根据自己的内容动
在下面的代码中,我尝试实现无限滚动。我遇到的问题是“document.height”和“window.height”返回相同的值。有人可以帮我解决我哪里出错了吗?
我有一个页面布局,其中两个 div 在一行中彼此相邻对齐。一列包含可变长度的文本,第二列包含图像。 标记基本上如下: texttext 我的
我是一名优秀的程序员,十分优秀!