swift - 当按下按钮但卡住时,尝试在 UIView.animate 中更改按钮标题和 label.center.x。为什么?斯威夫特 4 Xcode 9.4
问题描述
我的问题
我正在尝试在 touchInside button 时使用 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)
}
}
但是当我添加 .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)
}
}
请任何人都可以解释这种情况。
编辑:
动画工作但它的目的地总是在Đăng ký下的第一位(动画来自它的左侧或右侧,结果总是第一位)
解决方案
尝试完成“setTitle”。
UIView.animate(withDuration: 0.15, delay: 0, options: .curveLinear, animations: {
self?.underlineSignup.center.x -= (self?.underlineSignup.bounds.width)!
self?.view.layoutIfNeeded()
}){
//completion
self?.confirm.setTitle("Đăng ký", for: .normal)
}
推荐阅读
- c - 将结构传递给 Cosmic 编译器和 STM8 中的函数时出现“无效的间接操作数”错误
- php - php数组相关查询
- node.js - 我可以使用 express-rate-limit 为相同的路由设置多个速率限制吗?
- swift - 在视图控制器内移动视图
- java - 如何在 Spring sleuth 中从/到跟踪器中获取(提取)/设置 TraceContext
- node.js - 节点中的表单数据未显示
- python - 在 PNG 图像的情况下 OpenCV DNN 抛出异常
- javascript - HTML 用户输入类型限制
- javascript - AJAX 和 Java - 更新库存
- autohotkey - AutoHotKey - 带有箭头键的 LShift 和 RShift,无法按预期工作