【发布时间】:2015-02-19 12:04:24
【问题描述】:
我使用自动布局(xcode 6)在 xib 中设计了我的屏幕。我必须使用自动布局以编程方式重新设计屏幕。
我的屏幕上有 4 个水平视图。我必须隐藏第三个视图并使用自动布局将第四个视图移动到第三个视图的位置。
如何以编程方式更新约束。
【问题讨论】:
标签: ios iphone cocoa-touch uiview autolayout
我使用自动布局(xcode 6)在 xib 中设计了我的屏幕。我必须使用自动布局以编程方式重新设计屏幕。
我的屏幕上有 4 个水平视图。我必须隐藏第三个视图并使用自动布局将第四个视图移动到第三个视图的位置。
如何以编程方式更新约束。
【问题讨论】:
标签: ios iphone cocoa-touch uiview autolayout
您可以使用NSLayoutConstraint 并将适当的IBOutlet 分配给您的任何约束,然后在您想要更改视图大小的位置使用NSLayoutConstraint 的constant 属性来更改值。
例如
in your viewController.h
@property (strong, nonatomic) IBOutlet NSLayoutConstraint *tempConstraint;
some where in your viewController.m
tempConstraint.constant = 50; // or what ever you want
【讨论】: