2017-08-02 47 views
0

我使用UIImageWriteToSavedPhotosAlbum()将图像保存到设备的相册中。写入iOS相册的图像不正确

我有我的图像在一个数组中,他们显示在PageControl

navigationBar上的下载图标将图像保存为Photos

我可以将图像保存到Photos,但保存的图像不正确,即不保存特定索引处的图像。这是怎么了将所有图像的页面控制....

func scrollImagesWhileViewChange() { 

    for i in arrayOfURLImages { 

    self.pageControl.size(forNumberOfPages: arrayOfURLImages.count) 
     let scrollViewWidth:CGFloat = self.scrollView.frame.width 
     let scrollViewHeight:CGFloat = self.scrollView.frame.height 
     let index = arrayOfURLImages.index(of: i) 
     let imageA = UIImageView(frame: CGRect(x: CGFloat(index!) * scrollViewWidth, y:0,width:scrollViewWidth, height:scrollViewHeight)) 
     imageA.image = i 
     self.scrollView.addSubview(imageA) 
     self.imageToDownload = imageA 
     self.scrollView.contentSize = CGSize(width:self.scrollView.frame.width * CGFloat(arrayOfURLImages.count), height:self.scrollView.frame.height) 
     self.scrollView.delegate = self 
     self.pageControl.numberOfPages = arrayOfURLImages.count 
     self.pageControl.currentPage = 0 

} 
} 

在部分self.imageToDownload = imageA,我的图像分配给一个UIImageView变量。这就是我如何保存到“照片” ..

UIImageWriteToSavedPhotosAlbum(self.imageToDownload.image!, self, #selector(MyViewController.image(_:didFinishSavingWithError:contextInfo:)), nil)

这里的第一个参数应该得到正确的索引。但我无法弄清楚如何...

回答

0

当你点击下载按钮,你需要找出当前的页面控制索引,然后根据当前索引从arrayOfURLImages获取正确的图像,然后保存到相册。

尝试这个 -

UIImageWriteToSavedPhotosAlbum(arrayOfURLImages[self.pageControl.currentPage], self, #selector(MyViewController.image(_:didFinishSavingWithError:contextInfo:)), nil) 
+0

Yes..that的我很困惑与...什么我如何通过指数也与这部分UIImageWriteToSavedPhotosAlbum(self.imageToDownload.image变量“imageToDownload”! ... –

+0

感谢兄弟......现在正在工作...... –