i have array of image when i send the index of image from collectionView to another viewController which is display this image in full screen and i give the user ability to swipe between images but the issue on the swipe the swipe between images when change it is very fast i need to delay time on UIImageView when the image is changed any solution on that issue ?
the code below:
var ImageIndex:Int = 0 // this is index image which i send it from previous view controller
var arrayOfUrlImageLarge:[String] = []// this array which contain all the url of images
override func viewDidLoad() {
super.viewDidLoad()
imageView = UIImageView(image: UIImage(contentsOfFile: arrayOfUrlImageLarge[ImageIndex]))
imageView.contentMode = UIViewContentMode.ScaleAspectFill
let swipeGestureRight = UISwipeGestureRecognizer(target: self, action: #selector(ShowImageViewController.swipe(_:)))
swipeGestureRight.direction = .Right
let swipeGestureLeft = UISwipeGestureRecognizer(target: self, action: #selector(ShowImageViewController.swipe(_:)))
swipeGestureLeft.direction = .Left
self.imageView.addGestureRecognizer(swipeGestureLeft)
self.imageView.addGestureRecognizer(swipeGestureRight)
}
func swipe(gesture:UISwipeGestureRecognizer){
if gesture.direction == .Right {
if ImageIndex == 0 {
imageView.image = UIImage(data: NSData(contentsOfFile: arrayOfUrlImageLarge[ImageIndex])!)
}else {
ImageIndex = ImageIndex - 1
imageView.image = UIImage(data: NSData(contentsOfFile: arrayOfUrlImageLarge[ImageIndex])!)
}
}
if gesture.direction == .Left{
if ImageIndex >= arrayOfUrlImageLarge.count {
ImageIndex = arrayOfUrlImageLarge.count - 1
imageView.image = UIImage(data: NSData(contentsOfFile: arrayOfUrlImageLarge[ImageIndex])!)
}else {
ImageIndex = ImageIndex + 1
if ImageIndex >= arrayOfUrlImageLarge.count {
return
}
imageView.image = UIImage(data: NSData(contentsOfFile: arrayOfUrlImageLarge[ImageIndex])!)
}
}
}
Thank you