【问题标题】:Swift Animation - button with circle behindSwift Animation - 后面有圆圈的按钮
【发布时间】:2018-01-13 10:27:46
【问题描述】:

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

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

【问题讨论】:

    标签: swift animation button swift3 geometry


    【解决方案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")
        }
    }
    

    【讨论】:

      猜你喜欢
      • 2017-12-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-01-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多