【问题标题】:Showing error while using 'animateWithDuration'使用“animateWithDuration”时显示错误
【发布时间】:2015-01-28 12:09:20
【问题描述】:

我是 Swift 新手,所以无法解决问题,请指导我

像这样使用它

 UIView.animateWithDuration(duration, delay: 0.0, options: option, animations: { () -> Void in
        self.btnCallButton.hidden = true
       }, completion: nil)

并显示以下错误

Cannot invoke 'animateWithDuration' with an argument list of type '(Float, delay: FloatLiteralConvertible, options: UIViewAnimationOptions, animations: () -> Void, completion: NilLiteralConvertible)'

请提供所需的建议,并提供一些描述 swift 块的链接

【问题讨论】:

  • 注意 Swift!=Swing。请先阅读有用的标签弹出窗口,然后再将它们放在问题上。
  • Hidden 无论如何都不是动画的,所以你不需要动画代码。

标签: swift block uiviewanimation


【解决方案1】:

像这样:

UIView.animate(withDuration: 0.35) {
  // animate things
  return
}

【讨论】:

    【解决方案2】:

    在关闭结束时添加return

    UIView.animate(withDuration: duration, delay: 0.0, options: option, animations: { () -> Void in
        self.btnCallButton.hidden = true
        return
    }, completion: nil)
    

    【讨论】:

      【解决方案3】:

      Hidden 在 Swift 中是不可动画的。如果您想通过淡入/淡出隐藏/显示,请使用以下代码进行淡出

      UIView.animate(withDuration: duration, delay: 0.0, options: options, animations: {
          self.btnCallButton.isHidden = false
          self.btnCallButton.alpha = 0.0
      }, completion: { finished in
          self.btnCallButton.isHidden = true
      })
      

      并跟随淡入

      UIView.animate(withDuration: duration, delay: 0.0, options: options, animations: {
          self.btnCallButton.isHidden = false
          self.btnCallButton.alpha = 1.0
      }, completion: { finished in
      
      })
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多