-1

I am trying to use animateWithDuration closure in Swift. I have declared the arguments in the closure as mentioned in the Apple Book for Swift. However, I am still getting an error.

Below is the code snippet:

if(!isRotating){
 isRotating = true

 var myImageTemp :UIImageView  = self.myImage
UIView.animateWithDuration(0.5, delay: 1, options: UIViewAnimationCurve.EaseOut, animations: 
{
() in myImageTemp.transform = CGAffineTransformMakeRotation(angle + M_PI_2)
},
 completion: 
{
(Bool finished) in self.pathAnimation() })

 }           

It gives me an error:

Could find an overload that accepts the supplied arguments.

And also it tells me:

Implicit use of self in closure.

Can anybody help me with this?

Laurent Etiemble
  • 27,111
  • 5
  • 56
  • 81
  • You code and question format is a bit messy. Please tidy it up - it will make it easier for people to help you. – ColinE Jul 11 '14 at 11:30
  • possible duplicate of [Blocks on Swift (animateWithDuration:animations:completion:)](http://stackoverflow.com/questions/24071334/blocks-on-swift-animatewithdurationanimationscompletion) – Pascal Jul 11 '14 at 11:31

1 Answers1

1

Just try:

UIView.animateWithDuration(0.2,
    animations:
    {
        // your code.
    },
    completion:
    {
        (completed: Bool) in
        // your code.
    })

The (completed: Bool) in part indicates that the closure takes a Bool parameter labeled completed. If you are not interested in accessing the completed parameter, you can ignore it using an underscore.

UIView.animateWithDuration(0.2, 
animations: 
    {
        // your code.
    }, 
    completion: 
    { _ in
        // your code.
    })
Rafał Sroka
  • 39,540
  • 23
  • 113
  • 143
  • still unable to implement it properly. Still giving me an error : could not find overload for animateWithDuration that accepts these arguments. – Abhishek Gupta Jul 14 '14 at 13:25