[英]Changing Y position constraints programmatically
This is four button open new view between them. 这是四个按钮之间打开的新视图。
I set constraints through Xcode, and want to change position programatically, but it does not work. 我通过Xcode设置了约束,并且想以编程方式更改位置,但是它不起作用。 I am new, kindly help.
我是新来的,请帮忙。 I used
我用了
[_btn_patientInformation.translatesAutoresizingMaskIntoConstraints: NO];
NSLayoutConstraint *constraintCoordinatesCenterY =[NSLayoutConstraint constraintWithItem:_btn_patientInformation attribute:NSLayoutAttributeCenterY relatedBy:NSLayoutRelationEqual toItem:coordinatesView attribute:NSLayoutAttributeCenterY multiplier:1.0 constant:1];
But unfortunately it does not work. 但不幸的是,它不起作用。
Use outlet for the constraint you want to change. 将出口用于要更改的约束。
The outlet will be looking like this: 出口将如下所示:
@property (weak, nonatomic) IBOutlet NSLayoutConstraint * topPositionConstraint;
Connect the above constraint to the Y constraint in storyboard. 将以上约束连接到情节提要中的Y约束。
And to change the constraint, you can simply do: 要更改约束,您可以简单地执行以下操作:
topPositionConstraint.constant=yourValue;
and dont forget to call 别忘了打电话
[self.view layoutIfNeeded];
after the change in constraints. 改变约束之后。
Try to set the constraints this way: 尝试通过以下方式设置约束:
Now to move all these buttons up or down , you can simply change the top constraint for the first button. 现在,要上下移动所有这些按钮,您只需更改第一个按钮的顶部约束。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.