gpt4 book ai didi

cocoa - NSLayoutConstraint 将 centerX 约束到 super View 的另一侧

转载 作者:行者123 更新时间:2023-12-03 17:21:27 27 4
gpt4 key购买 nike

我目前可以将 View 的 centerX 限制在其 super View 的左侧,如下所示:

NSLayoutConstraint *con = [NSLayoutConstraint constraintWithItem:view
attribute:NSLayoutAttributeCentreX
relatedBy:NSLayoutRelationEqual
toItem:view.superview
attribute:NSLayoutAttributeLeft
multiplier:1
constant:20];

但这不允许我设置约束的优先级,因此限制很大。

我的问题是:如何使用视觉格式语言实现类似的效果(以便也可以设置优先级)?

另请注意:我希望仅通过单个约束即可实现此目的,以便稍后使用。

最佳答案

刚刚回想一下,调用 [con setPriority:priority] 的问题仅在约束已安装在 View 中时发生。

就我的目的而言,使用constraintWithItem:Attribute:RelatedBy...然后调用con.priority=priority效果很好。

尽管如此,了解如何使用 VFL 实现类似的目标(如果可能的话)仍然很有用

关于cocoa - NSLayoutConstraint 将 centerX 约束到 super View 的另一侧,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25578862/

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