如何从子视图设置父视图仅以编程方式使用而不使用 StoryBoard 拖动?
How Can i Set parent View from sub view Only use programmatically not use StoryBoard Dragging?
我尝试设置父视图,在 Storyboard 中我已经设置了它的高度。但是当我触摸蓝色按钮时我需要更改它,但我认为我添加 class not update constrain and view frame 或者它可能会更改 constrain 但不会 update 。我可以更新吗?
如果我的理解正确,您正在尝试更新在 Interface Builder 中设置的约束。为此,请将已设置的高度锚点拖到 ViewController。它看起来像这样:
@IBOutlet weak var yourViewHeightAnchor: NSLayoutConstraint!
比在你的更新功能中做:
func setupHeight() {
yourViewHeightAnchor.constant = 100 // Set your value here
yourView.layoutIfNeeded()
}
我尝试设置父视图,在 Storyboard 中我已经设置了它的高度。但是当我触摸蓝色按钮时我需要更改它,但我认为我添加 class not update constrain and view frame 或者它可能会更改 constrain 但不会 update 。我可以更新吗?
如果我的理解正确,您正在尝试更新在 Interface Builder 中设置的约束。为此,请将已设置的高度锚点拖到 ViewController。它看起来像这样:
@IBOutlet weak var yourViewHeightAnchor: NSLayoutConstraint!
比在你的更新功能中做:
func setupHeight() {
yourViewHeightAnchor.constant = 100 // Set your value here
yourView.layoutIfNeeded()
}