如何在不使用tableView.reloadData()的情况下在Swift中访问闭包之外的数据?

时间:2018-09-13 05:20:59

标签: ios swift

我正在使用UIViewController并从firebaseUI获取图像,并希望对其进行动画处理。但是我不知道该怎么做。请帮帮我。 如何不使用tableViewController实现它?

func getImage()
        {
           var Images = [String]()
            Images = ModelManager.getInstance().getImages(imageName)


            let storage = Storage.storage().reference()
            let storageRef = storage.child("images")

            for x in Images{


                let path = storageRef.child("\(x).jpg")         
                path.getData(maxSize: 1 * 1024 * 1024) { (data, error) in
                    if let error = error{
                        print(error.localizedDescription)
                        print(error)
                        return
                    }
                    else{
                            self.imageList += [UIImage(data: data!)!]
                    }
                }

            }


            myImageView.animationImages = imageList
            myImageView.animationDuration = 2
            myImageView.startAnimating()
        }

}

1 个答案:

答案 0 :(得分:1)

您可以满足以下要求。

 func getImage()
        {
            var Images = [String]()
            Images = ModelManager.getInstance().getImages(imageName)

            let storage = Storage.storage().reference()
            let storageRef = storage.child("images")

            for x in Images{
                let path = storageRef.child("\(x).jpg")
                path.getData(maxSize: 1 * 1024 * 1024) { (data, error) in
                    if let error = error{
                        print(error.localizedDescription)
                        print(error)
                        return
                    }else{
                        self.imageList += [UIImage(data: data!)!]
                    }

                    if x = Images.last {
                        myImageView.animationImages = imageList
                        myImageView.animationDuration = 2
                        myImageView.startAnimating()
                    }
                }
            }
        }