将 curveEaseIn 添加到 Swift Animation [英] Adding curveEaseIn to Swift Animation

查看:19
本文介绍了将 curveEaseIn 添加到 Swift Animation的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个旋转的图像,但它突然停止.我想添加curveEaseOut 以使其停止更平滑,但是当我添加动画:.curveEaseOut 时,出现错误.

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

我不断收到错误消息:类型 '() -> Void' 没有成员 'curveEaseOut'

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

推荐答案

如果你想指定 .curveEaseOut 你必须使用一个带有选项的 UIView 方法:

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)

这篇关于将 curveEaseIn 添加到 Swift Animation的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆