【问题标题】:Swift animation - Touchdown doesn't work wellSwift 动画 - 触地得分效果不佳
【发布时间】:2017-08-01 10:46:35
【问题描述】:

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

当我点击一个按钮时,后面有一个视图,当按钮不再聚焦时,视图被隐藏。我用 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() 并且按钮保持“焦点”。

我不知道如何解决它。

【问题讨论】:

  • 也许 touchesEnded() ?
  • 情节提要中没有 touchesEnded 功能:/ 你的意思是 Touch Cancel 吗?
  • 不,我的意思是你的 VC touchesEnded 中的函数
  • 或者使用touchUpInside中的一些代码实现另外一个函数touchUpOutside

标签: swift animation swift3 view touch-up-inside


【解决方案1】:

这应该可以解决问题:

button.addTarget(self, action: #selector(unpressed(sender:)), for: .touchUpOutside)

或使用情节提要将其连接到 touchUpOutside 的相同操作(未按下)

【讨论】:

  • 它不会触发动作?
  • 没有:/什么都没发生
猜你喜欢
  • 2019-04-12
  • 1970-01-01
  • 1970-01-01
  • 2015-01-11
  • 2018-05-05
  • 1970-01-01
  • 2011-09-17
  • 2014-01-01
  • 1970-01-01
相关资源
最近更新 更多