-1

I am new in Swift so could not figure out the problem , Please guide me

using It like

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

and it showing following error

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

please give the required suggestion and also provide some links which describe the blocks in swift

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
Anurag Bhakuni
  • 2,379
  • 26
  • 32

3 Answers3

0

Hidden is not animatable in Swift. If you want to hide/show via fade in/out use the following code for fadeout

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

and following for fadein

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

})
Karen Hovhannisyan
  • 1,140
  • 2
  • 21
  • 31
Zell B.
  • 10,266
  • 3
  • 40
  • 49
0

Add return at end of closure as

UIView.animate(withDuration: duration, delay: 0.0, options: option, animations: { () -> Void in
    self.btnCallButton.hidden = true
    return
}, completion: nil)
Karen Hovhannisyan
  • 1,140
  • 2
  • 21
  • 31
Mehul Thakkar
  • 12,440
  • 10
  • 52
  • 81
0

Like this:

UIView.animate(withDuration: 0.35) {
  // animate things
  return
}
Karen Hovhannisyan
  • 1,140
  • 2
  • 21
  • 31
Adam Waite
  • 19,175
  • 22
  • 126
  • 148