具有缩放和 alpha 的 UIView 动画

UIView animations with scale and alpha

我需要为 show/hide 视图 (UIButton) 制作动画,因此在视图比例从 0 变为 100%(显示)和反转(隐藏)的同时,alpha 从 0 变为 1。我可以单独制作每个动画,但如何将它们组合在一起?并且它必须 showing/hiding 纠正用户随机(并且可能如此之快,例如,隐藏动画未完成 - 显示动画开始)交互。任何帮助将不胜感激。

承接前面的评论,我尝试做一个简单的例子。 所以也许诀窍在于转换 "identity",它可以将视图恢复到原点,希望它能有所帮助

@IBAction func showButtonTapped(_ sender: Any) {
   UIView.animate(withDuration: 1.0, delay: 0.5, usingSpringWithDamping: 0.6, initialSpringVelocity: 1, options: [.curveEaseIn], animations: {
       self.yourView.transform = .identity
       self.yourView.alpha = 1

   }, completion: nil)
}

@IBAction func hideButtonTapped(_ sender: Any) {
   UIView.animate(withDuration: 1.0, delay: 0.5, usingSpringWithDamping: 0.6, initialSpringVelocity: 1, options: [.curveEaseOut], animations: {
       self.yourView.transform = CGAffineTransform.identity.scaledBy(x: 0.7, y: 0.7)
       self.yourView.alpha = 0
   })
}