Adding curveEaseIn to Swift Animation

跟風遠走 提交于 2021-02-08 03:41:15

问题


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!!


回答1:


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)


来源:https://stackoverflow.com/questions/42488066/adding-curveeasein-to-swift-animation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!