gpt4 book ai didi

ios - UIView Animate 只有在 IBAction 中时才会动画。我如何让它在我的情况下动画?

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

func pickWash() {

bottomChange = self.mapView.bottomAnchor.constraint(equalTo: self.view.bottomAnchor, constant: -350.0)
bottomChange.isActive = true

UIView.animate(withDuration: 10.0, animations: {
self.view.layoutIfNeeded()
self.waterlessLabel.isHidden = false
self.exteriorInterior.isHidden = false
self.exteriorOnly.isHidden = false
self.info.isHidden = false
self.blackLine.isHidden = false
self.extIntPrice.isHidden = false
self.extPrice.isHidden = false
self.confirmWash.isHidden = false
self.when.isHidden = false
self.timeChoice.isHidden = false

}, completion: nil)

}

func tester(){
self.pickWash()
}

实际上,我代码中的测试方法使用的是 Google 的 Place 自动完成 iOS,但我不想用无用的自动完成代码淹没我的代码。因此,当用户完成在 Google 的自动完成中输入他们的位置时,函数 pickwash() 被调用并且动画不起作用。只有当我在带有按钮的 IBAction 中使用它时,它才对我有用。有什么想法吗?

最佳答案

pickWash() 正在主线程以外的线程上(如 OP 评论中所确认)并且由于主线程是唯一允许在 UI 上工作的线程,因此行为未定义(这里没有任何反应)。您必须使用

将代码执行移动到主线程
func pickWash() {
// Code here is on a non-main thread
DispatchQueue.main.async {
// Code here is executed on the main thread
bottomChange = self.mapView.bottomAnchor.constraint(equalTo: self.view.bottomAnchor, constant: -350.0)
bottomChange.isActive = true

UIView.animate(withDuration: 10.0, animations: {
self.view.layoutIfNeeded()
self.waterlessLabel.isHidden = false
self.exteriorInterior.isHidden = false
self.exteriorOnly.isHidden = false
self.info.isHidden = false
self.blackLine.isHidden = false
self.extIntPrice.isHidden = false
self.extPrice.isHidden = false
self.confirmWash.isHidden = false
self.when.isHidden = false
self.timeChoice.isHidden = false

}, completion: nil)
}
}

func tester(){
self.pickWash()
}

关于ios - UIView Animate 只有在 IBAction 中时才会动画。我如何让它在我的情况下动画?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50070081/

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