【发布时间】:2020-05-22 02:15:48
【问题描述】:
在一个表格视图单元格中,我有一个文本视图,它的大小既减小了又随着 alpha 消失。
//self is tableviewcell
self.hiddenCon.isActive = true //this is a contraint of the textview, making it smaller
self.setNeedsUpdateConstraints()
self.layoutIfNeeded()
UIView.animate(withDuration: 0.25) {
self.textview.alpha = 0 //I also want to make it disappear while going smaller
self.layoutIfNeeded()
}
但它最终会变小,但没有 alpha 变化
【问题讨论】:
-
为什么要给
self.layoutIfNeeded()打两次电话? -
试试这个: UIView.animate(withDuration: 0.25) { self.hiddenCon.isActive = true self.textview.alpha = 0 //我也想让它在变小的时候消失 self.layoutIfNeeded( ) }
-
看起来问题只考虑 UITextView。只要您想更改 UITextView 的 alpha 及其框架,那么它的行为就会不正确。是否将 UITextView 包装到某个 UIView 并更改其 alpha 并不重要。只有一个快速修复方法是不更改 UITextView 的框架,而只更改超级视图包装器的框架。它不会是完美的,但可能已经足够好了。
-
@Rob 很公平,这里找不到示例项目github.com/dpyy/tabletest.git
标签: ios animation autolayout uikit