UIView 在动画块中忽略 setHidden
UIView ignoring setHidden when in animation block
我在 UIView
子类上有此代码:
override var hidden: Bool {
willSet {
DDLogDebug("Will set hidden=\(String(newValue)) on \(item?.name))")
}
didSet {
DDLogDebug("Did set hidden=\(String(hidden)) on \(item?.name))")
}
}
出于某种原因,我设置了 false
,但它仍然是 true
,如这些日志所示:
> Will set hidden=false on Optional("74D8E4CE-5E14-4914-8483-E9F66D2A79B7"))
> Did set hidden=true on Optional("74D8E4CE-5E14-4914-8483-E9F66D2A79B7"))
此问题的唯一特点是它仅在 运行 位于 UIView.animateWithDuration(...)
块内时发生。如果我删除动画,属性 设置正确。
对可能发生的事情有什么想法吗?快把我逼疯了,呵呵
编辑:
更多信息,我想隐藏的这个 UIView 是 UIStackView
的 arrangedSubview
。它在前几次尝试中工作正常,但突然停止工作,没有任何明显的模式。
这是 UIStackView 中的错误。
is another question describing the exact same issue I'm having. This 是针对此特定问题的公开雷达。
我找到的解决方案是避免将 hidden
设置为相同的值两次。
if (subview.hidden) {
subview.hidden = false
}
试试这个,对我有用
[UIView performWithoutAnimation:^{
arrangedSubview.hidden = isHidden;
}];
我在 UIView
子类上有此代码:
override var hidden: Bool {
willSet {
DDLogDebug("Will set hidden=\(String(newValue)) on \(item?.name))")
}
didSet {
DDLogDebug("Did set hidden=\(String(hidden)) on \(item?.name))")
}
}
出于某种原因,我设置了 false
,但它仍然是 true
,如这些日志所示:
> Will set hidden=false on Optional("74D8E4CE-5E14-4914-8483-E9F66D2A79B7"))
> Did set hidden=true on Optional("74D8E4CE-5E14-4914-8483-E9F66D2A79B7"))
此问题的唯一特点是它仅在 运行 位于 UIView.animateWithDuration(...)
块内时发生。如果我删除动画,属性 设置正确。
对可能发生的事情有什么想法吗?快把我逼疯了,呵呵
编辑:
更多信息,我想隐藏的这个 UIView 是 UIStackView
的 arrangedSubview
。它在前几次尝试中工作正常,但突然停止工作,没有任何明显的模式。
这是 UIStackView 中的错误。
我找到的解决方案是避免将 hidden
设置为相同的值两次。
if (subview.hidden) {
subview.hidden = false
}
试试这个,对我有用
[UIView performWithoutAnimation:^{
arrangedSubview.hidden = isHidden;
}];