2017-08-05 83 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") 
    } 
}