Swift cant resolve CurveEaseIn in UIView.animateWithDuration when using parameter from function inside animation block

527 views Asked by At

I am trying to pass parameter to function to change layout constraint in animation block dynamically.

This works:

func moveKeyboard (up: Bool, newMargin: Int)
{

    UIView.animateWithDuration(0.2, delay: 0, options: .CurveEaseIn, animations: {

        self.topMarginConstraint.constant=10;

        }, completion: { finished in
            println("Animation end!")
    })

}

and this doesn't (i get error "Could not find member CurveEaseIn"):

 func moveKeyboard (up: Bool, newMargin: Int)
{

    UIView.animateWithDuration(0.2, delay: 0, options: .CurveEaseIn, animations: {

        self.topMarginConstraint.constant=newMargin;

        }, completion: { finished in
            println("Animation end!")
    })

 }

How should i define my function to be able to use newMargin parameter inside animation block?

1

There are 1 answers

0
Sohel L. On BEST ANSWER

It's because, the "constant" is of type "CGFLoat" and you are passsing "Int":

func moveKeyboard (up: Bool, newMargin: CGFloat)
    {

        UIView.animateWithDuration(0.2, delay: 0, options: UIViewAnimationOptions.CurveEaseIn, animations: {

            self.topMarginConstraint.constant = newMargin;

            }, completion: { finished in
                println("Animation end!")
        })

    }

Check this out it's working fine.