如何在 iOS 中更改动画 gif 图像的不透明度 [英] How to change opacity of animated gif images in iOS

查看:25
本文介绍了如何在 iOS 中更改动画 gif 图像的不透明度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

相关代码如下.我希望每个图像在整个动画循环中出现时都具有淡入效果.运行此代码时,gif 动画效果有效,但不透明度更改代码无效.任何帮助将不胜感激.谢谢!

Relevant code below. I want each image to have a fade-in affect while they appear in the overall animation cycle. When running this code, the gif animation affect works, but the opacity changing code does not. Any help would be greatly appreciated. Thanks!

import UIKit

class View1: UIViewController {
    @IBOutlet weak var imageView: UIImageView!

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
        var imagesNames = ["ALA0.jpeg", "ALA1.jpeg", "ALA2.png", "ALA3.png", "ALA4.png", "ALA5.png", "ALA6.png", "ALA7.png", "ALA8.png", "ALA9.png", "ALA10.png"]
        var images = [UIImage]()

        for i in 0..<imagesNames.count{
            images.append(UIImage(named: imagesNames[i])!)
            imageView.alpha = 0
            UIImageView.animate(withDuration: 1.0) {
                self.imageView.alpha = 1
            }
        }

        imageView.animationImages = images
        imageView.animationDuration = 6.0

        self.imageView.startAnimating()
    }
}

推荐答案

试试下面的代码:已更新

    for i in 0..<imagesNames.count{

        images.append(UIImage(named: imagesNames[i])!)
        imageView.alpha = 0
        UIImageView.animate(withDuration: 0.9, delay: 0, options: [UIViewAnimationOptions.curveEaseInOut,.repeat], animations: { 
             self.imageView.alpha = 1
            }, completion: nil)

    }

       imageView.animationImages = images
       imageView.animationDuration = 5 // I am using 5 images to perform animation

注意:从上面的代码中,你会得到一个帧到帧的华丽效果,你必须使用动画持续时间和总动画持续时间来同步效果.

Note: From the above code.You will get a flashy effect frame to frame and you have to play with animation time duration and total animation duration to sync the effect.

这篇关于如何在 iOS 中更改动画 gif 图像的不透明度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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