gpt4 book ai didi

ios - 以编程方式更改 Y 位置约束

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

enter image description here
这是它们之间打开新 View 的四个按钮。

我通过 Xcode 设置约束,并想以编程方式更改位置,但它不起作用。我是新人,请帮助。我用过

[_btn_patientInformation.translatesAutoresizingMaskIntoConstraints: NO];
NSLayoutConstraint *constraintCoordinatesCenterY =[NSLayoutConstraint constraintWithItem:_btn_patientInformation attribute:NSLayoutAttributeCenterY relatedBy:NSLayoutRelationEqual toItem:coordinatesView attribute:NSLayoutAttributeCenterY multiplier:1.0 constant:1];

但不幸的是它不起作用。

最佳答案

对要更改的约束使用导出。

socket 看起来像这样:

 @property (weak, nonatomic) IBOutlet NSLayoutConstraint * topPositionConstraint;

将上述约束连接到 Storyboard 中的 Y 约束。

要更改约束,您可以简单地执行以下操作:

  topPositionConstraint.constant=yourValue;

别忘了打电话

    [self.view layoutIfNeeded];

约束条件改变后。

尝试以这种方式设置约束:

  • 选择顶部按钮,并给出前导、尾随、顶部、高度、宽度约束。

enter image description here

  • 现在选择第二个按钮,按住 Ctrl 键将其拖到第一个按钮上,然后松开鼠标,然后选择垂直间距和前导约束。

enter image description here enter image description here

  • 对第三个按钮执行相同的操作,不同之处在于您按住 Ctrl 键将第三个按钮拖到第二个按钮。

enter image description here

现在要向上或向下移动所有这些按钮,您只需更改第一个按钮的顶部约束即可。

关于ios - 以编程方式更改 Y 位置约束,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34225426/

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