【发布时间】:2016-07-21 09:12:39
【问题描述】:
当我将图像索引从 collectionView 发送到另一个 viewController 时,我有图像数组,该 viewController 全屏显示此图像,并且我让用户能够在图像之间滑动,但滑动时出现问题 更改时图像之间的滑动非常快我需要在更改图像时延迟 UIImageView 上的时间关于该问题的任何解决方案?
下面的代码:
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
覆盖 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])!)
}
}
}
谢谢
【问题讨论】:
标签: swift swipe-gesture