gpt4 book ai didi

swift - 尝试在按下按钮时更改 UIView.animate 中的 Button Title 和 label.center.x 但卡住了。为什么? swift 4 Xcode 9.4

转载 作者:行者123 更新时间:2023-11-30 11:12:07 25 4
gpt4 key购买 nike

我的问题

我正在尝试在 touchInside 按钮时使用 UIView.animate(..) 做一些带有标签的动画。一切仍然正常,直到我添加一行:“self?.confirm.setTitle("Đăng nhập", for: .normal)。动画不起作用。

我的意志

我希望Đăng Ký下面的黄色下划线切换到Đăng nhập下面。

代码是好的

@IBAction func signUpAction(_ sender:Any?){
if (signup == false){
signup = true
UIView.animate(withDuration: 0.4, delay: 0, options: [.curveEaseIn], animations: {[weak self] in
self?.underlineSignup.center.x -= (self?.underlineSignup.bounds.width)!
self?.view.layoutIfNeeded()
}, completion: nil)
}
}
@IBAction func signInAction(_ sender:Any?){
if (signup == true){
signup = false
UIView.animate(withDuration: 0.4, delay: 0, options: [.curveEaseIn], animations: {[weak self] in
self?.underlineSignup.center.x += (self?.underlineSignup.bounds.width)!
self?.view.layoutIfNeeded()
}, completion: nil)
}
}

It work

但是当我添加 .setTitle

@IBAction func signUpAction(_ sender:Any?){
if (signup == false){
signup = true
UIView.animate(withDuration: 0.4, delay: 0, options: [.curveEaseIn], animations: {[weak self] in
self?.underlineSignup.center.x -= (self?.underlineSignup.bounds.width)!
self?.confirm.setTitle("Đăng ký", for: .normal)
self?.view.layoutIfNeeded()
}, completion: nil)
}
}
@IBAction func signInAction(_ sender:Any?){
if (signup == true){
signup = false
UIView.animate(withDuration: 0.4, delay: 0, options: [.curveEaseIn], animations: {[weak self] in
self?.underlineSignup.center.x += (self?.underlineSignup.bounds.width)!
self?.confirm.setTitle("Đăng nhập", for: .normal)
self?.view.layoutIfNeeded()
}, completion: nil)
}
}

It stuck, only the title of button confirm change, the underline doesn't move

请任何人都可以解释这种情况。

编辑:

动画正在运行,但它的目的地始终是Đăng ký下的第一个位置(动画来自其左侧或右侧,结果始终位于第一个位置)

最佳答案

我想我知道是怎么回事。因为在setTitle中有view的updateFrame Constraintlayout。我在构建按钮时有一个约束布局。当我 setTitles 时,它使用约束重置 View 。我就是这么想的。

关于swift - 尝试在按下按钮时更改 UIView.animate 中的 Button Title 和 label.center.x 但卡住了。为什么? swift 4 Xcode 9.4,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52081112/

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