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的自动填充功能iOS,但我不想使用无用的自动填充代码来填充我的代码。因此,当用户在Google的自动完成中输入他们的位置时,调用函数pickwash()并且动画不起作用。当我在带有按钮的IBAction中使用它时,它才对我有用。有什么想法吗?
答案 0 :(得分:1)
isHidden
无法使用alpha
动画,请参阅以下代码。
我注意到你把时间设置为10.0和10这么长。
func pickWash() {
UIView.animate(withDuration: 1.0, animations: {
self.view.layoutIfNeeded()
self.waterlessLabel.alpha = 1
self.exteriorInterior.alpha = 1
self.exteriorOnly.alpha = 1
self.info.alpha = 1
self.blackLine.alpha = 1
self.extIntPrice.alpha = 1
self.extPrice.alpha = 1
self.confirmWash.alpha = 1
self.when.alpha = 1
self.timeChoice.alpha = 1
}, completion: nil)
}
func tester(){
self.pickWash()
}
答案 1 :(得分:1)
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()
}
答案 2 :(得分:0)
如果要为约束设置动画,您只需更新常量属性即可。这是一些示例代码:
@IBOutlet private weak var mapViewBottomConstraint; // If you are not using InterfaceBuilder, then hold a reference to the bottom constraint when you add it to your view.
func pickWash() -> Void {
self.mapViewBottomConstraint.constant = -350.0; // or whatever is appropriate here.
UIView.animate(withDuration: 1.0, animations: { [weak self] in
self?.view.layoutIfNeeded()
// do your stuff
}, completion: nil)
}