无法在swift 3中使用SDWebImage为gif制作动画

时间:2017-09-06 06:19:15

标签: swift swift3 sdwebimage

已加载图片但未能为gif制作动画

<!doctype html>
<html lang="en">

<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>jQuery UI Sortable - Default functionality</title>
  <link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
  <link rel="stylesheet" href="/resources/demos/style.css">
  <style>
    #slides {
      list-style-type: none;
      margin: 0;
      padding: 0;
      width: 60%;
    }
    
    #slides li {
      margin: 0 3px 3px 3px;
      padding: 0.4em;
      padding-left: 1.5em;
      font-size: 1.4em;
      height: 18px;
    }
    
    #slides li span {
      position: absolute;
      margin-left: -1.3em;
    }
  </style>
  <script src="https://code.jquery.com/jquery-1.12.4.js"></script>
  <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
  <script>
    $(function() {

      $("#slides").sortable({
        disabled: $("#slides li").length == 1
      });

      $('#slides').on('click', function() {
        $("#slides").sortable("refresh");
        $("#slides").sortable("option", "disabled", $("#slides li").length == 1);
      });

    });
  </script>
</head>

<body>

  <ul id="slides">
    <li class="ui-state-default"><span class="ui-icon ui-icon-arrowthick-2-n-s list-group-item"></span>Item 1</li>

  </ul>

  <button>add</button>
</body>

</html>

2 个答案:

答案 0 :(得分:2)

如果要求坚持SDWebImage,那么我会注意到(如library github中所述):

  

动画图片(GIF)支持

     
      
  • 从4.0版本开始,我们依赖 FLAnimatedImage   照顾我们的动画图片。

         

    ...

  •   
  • 要使用它,只需确保使用 FLAnimatedImageView 而不是   的UIImageView。

  •   

<强> FLAnimatedImage:

要在Swift中使用它的简单代码,您可以查看answer

答案 1 :(得分:2)

let url = Bundle.main.url(forResource: "play", withExtension: "gif")

        DispatchQueue.main.async {

            self.image.sd_setImage(with: url!)
        }

        let imageData = try? Data(contentsOf: Bundle.main.url(forResource: "play", withExtension: "gif")!)
        let advTimeGif = UIImage.gifImageWithData(imageData!)
        let imageView2 = UIImageView(image: advTimeGif)
        imageView2.frame = CGRect(x: 20.0, y: 420.0, width: self.view.frame.size.width - 40, height: 150.0)
        view.addSubview(imageView2)

enter image description here