OStack程序员社区-中国程序员成长平台

标题: ios - 如何调整 UIView 的 Y anchor ? [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-11 20:20
标题: ios - 如何调整 UIView 的 Y anchor ?

我可以用什么来替换 anchor 以将 inputContainerView 提高一点。目前它的中心看起来不正确。

这是我所拥有的代码:

inputsContainerView.centerXAnchor.constraint(equalTo: view.centerXAnchor).isActive = true
inputsContainerView.centerYAnchor.constraint(equalTo: view.centerYAnchor).isActive = true



Best Answer-推荐答案


有一个额外的参数可以相对于另一个 View 调整 anchor 。请使用自动完成功能并仔细阅读建议及其描述。示例:

inputsContainerView.centerXAnchor.constraint(equalTo: view.centerXAnchor, constant: 10).isActive = true
inputsContainerView.centerYAnchor.constraint(equalTo: view.centerYAnchor, constant: -10).isActive = true

将 10 或 -10 替换为适合您要求的值。约束的 constant 参数相对于提到的 anchor 移动 anchor 。


提示:值将您的 anchor 向上移动为水平 anchor ,向左侧移动垂直 anchor 。正值则相反。

关于ios - 如何调整 UIView 的 Y anchor ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51220809/






欢迎光临 OStack程序员社区-中国程序员成长平台 (http://ostack.cn/) Powered by Discuz! X3.4