gpt4 book ai didi

ios - Swift UIView Constraint Constant Height Changing时间获取LayoutConstraints警告

转载 作者:行者123 更新时间:2023-11-28 11:30:43 25 4
gpt4 key购买 nike

我的场景,我在 storyboard 中实现了 UIView,高度恒定为 90。在这个 UIView 中,我有两个 UIView height 25 和另一个 UICollectionView 54。现在,我试图以编程方式将基本 UIView 高度从 90 降低到 35,但我收到了 LayoutConstraints 警告。为正确的方法提供一些解决方案。

下面是我正在使用的代码

BottomGalleryHeight.constant = 90 // Changing to 35
photoGalleryView.layoutIfNeeded()

我的警告错误

[LayoutConstraints] 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.
(
"<NSLayoutConstraint:0x282679360 UIView:0x102f30880.height == 25 (active)>",
"<NSLayoutConstraint:0x282679450 UIView:0x102f306a0.height == 35 (active)>",
"<NSLayoutConstraint:0x2826794a0 V:|-(0)-[UIView:0x102f30880] (active, names: '|':UIView:0x102f306a0 )>",
"<NSLayoutConstraint:0x28267e210 V:[UIView:0x102f30880]-(10)-[UICollectionView:0x10385e000] (active)>",
"<NSLayoutConstraint:0x28267d450 V:[UICollectionView:0x10385e000]-(1)-| (active, names: '|':UIView:0x102f306a0 )>"
)

Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x282679360 UIView:0x102f30880.height == 25 (active)>

Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKitCore/UIView.h> may also be helpful.

最佳答案

这里是你如何让它工作,

class VC: UIViewController {
@IBOutlet weak var outerViewHeight: NSLayoutConstraint!
@IBOutlet weak var innerViewHeight: NSLayoutConstraint!
@IBOutlet weak var collectionViewHeight: NSLayoutConstraint!

override func viewDidLoad() {
super.viewDidLoad()
}

@IBAction func onTapButton(_ sender: UIButton) {
outerViewHeight.constant = 35.0
innerViewHeight.constant = 10.0
collectionViewHeight.constant = 25.0

UIView.animate(withDuration: 0.3) {
self.view.layoutIfNeeded()
}
}
}

enter image description here

关于ios - Swift UIView Constraint Constant Height Changing时间获取LayoutConstraints警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56804208/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com