2017-08-05 66 views
0

我试图去创造比应用“音乐”同样的效果圈:斯威夫特动画 - 按钮背后

enter image description here enter image description here

当我点击一个按钮,有后视图和当按钮不再被聚焦时,视图被隐藏。我使用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函数,但没有结果。我不知道如何解决它。

回答

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") 
    } 
}