Jupiter869
Jupiter869

Reputation: 657

Adding curveEaseIn to Swift Animation

I have an image that rotates but it stops abruptly. I'd like to add curveEaseOut to make it stop smoother, but when I add the animations: .curveEaseOut, I get an error.

func rotateRight () {
    let rotation = 90.0
    let transform = imageGearRight.transform
    let rotated = transform.rotated(by: CGFloat(rotation))
    UIView.animate(withDuration: 0.5, animations: .curveEaseOut) {
        self.imageGearRight.transform = rotated
    }
}

I keep getting an error: Type '() -> Void' has no member 'curveEaseOut'

I've also tried this code, but I get an error also:

    UIView.animate(withDuration: 0.5, animations: UIViewAnimationCurve.easeOut) {
        self.imageGearRight.transform = rotated
    }

Not sure what I am missing. Any help would be appreciated!!

Upvotes: 2

Views: 2268

Answers (1)

Nikolai Ruhe
Nikolai Ruhe

Reputation: 81878

If you want to specify .curveEaseOut you have to use a UIView method that takes options:

UIView.animate(withDuration: 0.5,
               delay: 0,
               options: [ .curveEaseOut ],
               animations: {
                   self.imageGearRight.transform = rotated
               },
               completion: nil)

Upvotes: 3

Related Questions