1
我似乎無法讓我的滑動手勢識別器爲表格視圖單元格內的圖像視圖工作。在UITableViewCell中滑動手勢UIImageView
我已經證實,images.count> 1.
if images.count > 0 {
let imageUrlString = images[0] as String
let imageUrl = NSURL(string: imageUrlString)
imageCell.cellImageView.sd_setImageWithURL(imageUrl, placeholderImage: UIImage(named: "placeholder"))
if images.count > 1 {
let swipeRightGestureRecognizer = UISwipeGestureRecognizer(target: self, action: #selector(swipeRight))
swipeRightGestureRecognizer.direction = .Right
imageCell.cellImageView.addGestureRecognizer(swipeRightGestureRecognizer)
let swipeLeftGestureRecognizer = UISwipeGestureRecognizer(target: self, action: #selector(swipeLeft))
swipeLeftGestureRecognizer.direction = .Left
imageCell.cellImageView.addGestureRecognizer(swipeLeftGestureRecognizer)
}
} else {
imageCell.cellImageView.image = UIImage(named: "placeholder")
}
swipeLeft和swipeRight
func swipeLeft(sender: UISwipeGestureRecognizer) {
imageView = sender.view as! UIImageView
transition.subtype = kCATransitionFromRight
imageView.layer.addAnimation(transition, forKey: nil)
if imageIndex == images.count - 1 {
let urlString = images[0] as String
let url = NSURL(string: urlString)
imageView.sd_setImageWithURL(url, placeholderImage: UIImage(named: "placeholder"))
imageIndex = 0
} else {
let urlString = images[imageIndex + 1] as String
let url = NSURL(string: urlString)
imageView.sd_setImageWithURL(url, placeholderImage: UIImage(named: "placeholder"))
imageIndex += 1
}
}
func swipeRight(sender: UISwipeGestureRecognizer) {
imageView = sender.view as! UIImageView
transition.subtype = kCATransitionFromLeft
imageView.layer.addAnimation(transition, forKey: nil)
if imageIndex == 0 {
let urlString = images.last! as String
let url = NSURL(string: urlString)
imageView.sd_setImageWithURL(url, placeholderImage: UIImage(named: "placeholder"))
imageIndex = images.count - 1
} else {
let urlString = images[imageIndex - 1] as String
let url = NSURL(string: urlString)
imageView.sd_setImageWithURL(url, placeholderImage: UIImage(named: "placeholder"))
imageIndex -= 1
}
}