gpt4 book ai didi

Swift:使用动画以编程方式更改特定约束

转载 作者:行者123 更新时间:2023-11-30 11:23:57 27 4
gpt4 key购买 nike

我有两个 imageview,在两个 imageViewz 之间​​我有一个 5pt 的小对象“DragButton”。

在左侧的 ImageView 中,我对针对拖动按钮的右边缘有一个约束。

我想在代码中更改此约束,我想删除将其绑定(bind)到拖动按钮的此约束,并将其替换为将其绑定(bind)到右屏幕边缘的约束,并且我希望约束为0 pt 就像 l 图像占据屏幕的整个宽度。

我想给他一个动画,这里有两张截图来帮助你理解:

first picture

second picture

最佳答案

在 Storyboard中添加这两个约束(也可以在代码中创建)
1) Image.right <-> ScreenEdge.right(名为pinRight),
2) Image.right <-> DragButton.left(名为pinRightWithDragButton)。
3)将pinRight的优先级设置为999(小于pinRightWithDragButton)(两者都存在而不警告)
4) 创建两者的IBOutlet,不要使IBOutlet weak,删除weak
5) 在代码中一次启用一个并禁用另一个

func makeImageView(fullScreen: Bool) {
pinRight.isActive = fullScreen
pinRightWithDragButton.isActive = !fullScreen
UIView.animate(withDuration: 0.5) {
view.layoutIfNeeded()
}
}

*或者您也可以更改它们的优先级。

关于Swift:使用动画以编程方式更改特定约束,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50960391/

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