Swift - 动画 ImageView

标签 swift image jquery-animate transform

这只是我遇到的一个关于为我当前的应用程序设置设置移动背景 ImageView 的动画的快速问题。本质上,我想让当前的静止背景 ImageView 无休止地向上滚动到开始位置;但我正在努力将它们拼凑在一起。有人可以帮助我吗?

 class Flash: UIViewController {
@IBOutlet weak var arrowImage: UIImageView!

    var arrow1: UIImage!
    var arrow2: UIImage!
    var arrow3: UIImage!
    var images: [UIImage]!
    var animatedImage: UIImage!
    override func viewDidLoad() {
        super.viewDidLoad()
        toggleFlash()
        arrow1 = UIImage(named: "Arrow1.png")
        arrow2 = UIImage(named: "Arrow2.png")
        arrow3 = UIImage(named: "Arrow3.png")
        images = [arrow1, arrow2, arrow3]
       animatedImage = UIImage.animatedImage(with: images, duration: 1.0)
        arrowImage.image = animatedImage

    }

    func blinkScreen(){

    UIView.animate(withDuration: 1, delay: 0, options: [.repeat, .curveLinear], animations: {

    }) { _ in
    }
}

最佳答案

好吧,我想我明白你想要什么。

首先,持续时间参数是动画每次迭代的持续时间。其次,UIView.animate(...) 不会重复动画,除非您将 .repeat 选项添加到 options 参数。

因此,为了实现更接近您想要的效果,请将代码更新为:

func blinkScreen()
    UIView.animate(withDuration: 1, delay: 0, options: [.repeat, .curveLinear], animations: {
        self.imageV.transform = CGAffineTransform(translationX: 0, y: -10)
    }) { _ in
        self.imageV.transform = .identity
    }
}

如果您想为上下移动设置动画,请使用 .autoreverse 选项(也可能是 .curveEaseInOut):

func blinkScreen()
    UIView.animate(withDuration: 1, delay: 0, options: [.repeat, .autoreverse, .curveEaseInOut], animations: {
        self.imageV.transform = CGAffineTransform(translationX: 0, y: -10)
    }) { _ in
        self.imageV.transform = .identity
    }
}

关于Swift - 动画 ImageView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54970478/

相关文章:

jquery - 停止 jQuery 中的递归动画

ios - 使用对象映射器模型生成请求

swift - AVAudioRecorder 录制非常大的 m4a 文件

image - 在 Umbraco 中使用 Razor 测试图像裁剪是否存在

swift - 'InfoKey' 不是 'UIImagePickerController' 的成员类型

jquery - 窗口滚动、if 语句和动画无法正常工作

jquery - 如何动画/显示隐藏的 div?

swift - 更新一些数据后如何刷新应用程序中的数据?

ios - 当单元格被重用时,我在 TableViewCell 中的心脏按钮状态被保存

html - 如何调整内联图像的大小产品描述中的屏幕截图