Swift Animation - 后面有圆圈的按钮

标签 swift animation button swift3 geometry

我正在尝试创建与“音乐”应用程序相同的效果:

enter image description here enter image description here

当我点击一个按钮时,后面有一个 View ,当按钮不再聚焦时, View 被隐藏。我使用 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)
      }
   }

问题是,当我单击并按住焦点,然后滑出按钮时,未调用函数 unpressed() 并且按钮保持“焦点”状态。

我也尝试添加 touchUpOutside 功能但没有结果。我不知道如何修复它。

最佳答案

对我来说这很有效(我更喜欢离开按钮时退出)

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

关于Swift Animation - 后面有圆圈的按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45524482/

相关文章:

swift - 这是 UITextView 透明度错误吗?

python - Matplotlib 动画无法正确保存

android - 无法检测到两个 View 重叠

javascript - 如何在 javascript 中创建删除/删除功能按钮?可以删除元素的按钮

javascript - 如果选择按钮,jQuery 显示/隐藏选项

ios - 无法打开文件 “***.app”,因为您没有查看它的权限

ios - UIImageJPEGRepresentation Swift 的错误循环

android - 将特定按钮添加到滚动 PreferenceScreen 的底部

ios - iMessage 中的导航栏高度 (iOS 10)

animation - 加载声音时,Cocos2d应用程序卡住