我正在尝试创建与“音乐”应用相同的效果:
当我点击按钮时,后面有一个视图,当按钮不再聚焦时,视图被隐藏。我使用TouchUpInside和TouchDown功能执行此操作。
@IBAction func pressed(_ sender: UIButton) {
UIView.animate(withDuration: 0.25, animations: {
self.backgroundMoreView.alpha = 0.0
self.backgroundMoreView.transform = CGAffineTransform(scaleX:
1.2, y: 1.2)
sender.transform = CGAffineTransform.identity
}) { (_) in
self.backgroundMoreView.transform = CGAffineTransform.identity
}
}
@IBAction func unpressed(_ sender: UIButton) {
UIView.animate(withDuration: 0.25) {
self.backgroundMoreView.alpha = 0.3
sender.transform = CGAffineTransform(scaleX: 0.8, y:
0.8)
}
}
问题在于,当我单击并按住焦点,然后我滑出按钮时,函数未按下()不会被调用,按钮保持“聚焦”状态。
我还尝试添加touchUpOutside
函数,但没有结果。我不知道如何解决它。
答案 0 :(得分:1)
对我来说这是有效的(我更喜欢离开按钮时退出)
@IBAction func touchDown(_ sender: UIButton) {
UIView.animate(withDuration: 0.25, animations: {
self.background.alpha = 1.0
}) { (_) in
print("do")
}
}
@IBAction func touchDragExit(_ sender: UIButton) {
UIView.animate(withDuration: 0.25, animations: {
self.background.alpha = 0.0
}) { (_) in
print("away")
}
}