gpt4 book ai didi

swift - 以编程方式使用自动布局在 UIVIew 中将 UITextField 设置为中心

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

我有一个 TextField,必须设置在 UIView 的中心
这是约束

var dict = ["txtHome" : txtHome]
self.view.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("H:|-[txtHome]-|", options: nil, metrics: nil, views: dict))
self.view.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("V:|-(>=90,<=100)-[txtHome(20)]-|", options: nil, metrics: nil, views: dict))

但是我得到了日志,

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. (Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints) 
(
"<NSLayoutConstraint:0x7966d210 V:|-(<=100)-[UITextField:0x79666440] (Names: '|':UIView:0x796637d0 )>",
"<NSLayoutConstraint:0x7966d280 V:[UITextField:0x79666440(20)]>",
"<NSLayoutConstraint:0x7966d240 UIView:0x796637d0.bottomMargin == UITextField:0x79666440.bottom>",
"<NSLayoutConstraint:0x7966e880 'UIView-Encapsulated-Layout-Height' V:[UIView:0x796637d0(480)]>"
)

Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x7966d240 UIView:0x796637d0.bottomMargin == UITextField:0x79666440.bottom>

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

我不明白他试图告诉我什么来帮助我摆脱困境。

最佳答案

要删除输出,只需添加txtHome.setTranslatesAutoresizingMaskIntoConstraints(false)

在没有约束的情况下, View 使用自动调整大小掩码进行布局 UIView reference , guide

关于swift - 以编程方式使用自动布局在 UIVIew 中将 UITextField 设置为中心,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28765840/

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