问题描述
限时送ChatGPT账号..我正在隐藏和取消隐藏 dropDownView(由文本字段和按钮组成的 UIView)基于在 Segment Control 中点击的 Segment.以下是视图层次结构:-
I am hiding and unhiding dropDownView(UIView consisting of textfield and button) based on Segment tapped in Segment Control. Following is the view hierarchy :-
以下是隐藏/取消隐藏 dropDownView 的代码:-
Following is the code which hides/unhides dropDownView :-
private func animateView(view: UIStackView, toHidden hidden: Bool) {
UIView.animate(withDuration: 0.25)
{
let firstView = view.arrangedSubviews[0]
firstView.isHidden = hidden
}
}
func segmentValueChanged(_ sender: UISegmentedControl) {
let segmentSelected = segmentControl.selectedSegmentIndex
switch segmentSelected {
case 0:
animateView(view: mainStackView, toHidden: true)
case 1:
animateView(view: mainStackView, toHidden: true)
case 2:
animateView(view: mainStackView, toHidden: true)
case 3:
animateView(view: mainStackView, toHidden: false)
default:
break
}
}
我面临的问题是在更改段超过 10-15 次后,上述代码停止工作并且下拉视图与段控制重叠,我不知道为什么.感谢您对理解此问题的任何帮助.
Problem which I am facing is after changing segments over 10-15 times the above code stops working and DropDown View overlaps with Segment Control and I am not sure why. Any help to understand this issue is appreciated.
我也试过了
<强>1.setNeedsLayout,
2.设置NeedsDisplay和
3. 将 dropDownView 的高度约束的优先级从 999 降低到1000
推荐答案
似乎在 completionClosure 中的附加设置 isHidden 修复了该问题(Swift 5 语法):
Seem the additional setting isHidden in completionClosure fixes that issue (Swift 5 syntax):
private func animateView(view: UIStackView, toHidden hidden: Bool) {
let firstView = view.arrangedSubviews[0]
UIView.animate(withDuration: 0.25) {
firstView.isHidden = hidden
view.layoutIfNeeded()
} completion {
firstView.isHidden = hidden
}
}
这篇关于UIStackView 隐藏/取消隐藏排列子视图问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
更多推荐
[db:关键词]
发布评论