Я хотел бы иметь SwipeImageGallery
внутри моего CustomShareExtensionViewController
, но сейчас он не обнаруживает gestures
, и я не знаю почему.
Изображения:
let images: [UIImage] = [
UIImage(named: "avocadoImage")!, // 0
UIImage(named: "beerImage")!, // 1
UIImage(named: "bikeImage")!, // 2
UIImage(named: "christmasImage")!, // 3
UIImage(named: "dressImage")!, // 4
UIImage(named: "giftImage")!, // 5
UIImage(named: "rollerImage")!, // 6
UIImage(named: "shirtImage")!, // 7
UIImage(named: "shoeImage")!, // 8
UIImage(named: "travelImage")!, // 9
UIImage(named: "iconRoundedImage")!,
]
ViewDidLoad:
let swipeRight = UISwipeGestureRecognizer(target: self, action: #selector(respondToSwipeGesture))
swipeRight.direction = UISwipeGestureRecognizer.Direction.right
self.view.addGestureRecognizer(swipeRight)
let swipeLeft = UISwipeGestureRecognizer(target: self, action: #selector(respondToSwipeGesture))
swipeLeft.direction = UISwipeGestureRecognizer.Direction.left
self.view.addGestureRecognizer(swipeLeft)
responseToGesture :
@objc func respondToSwipeGesture(gesture: UIGestureRecognizer) {
if let swipeGesture = gesture as? UISwipeGestureRecognizer {
switch swipeGesture.direction {
case UISwipeGestureRecognizer.Direction.left:
if currentImage == images.count - 1 {
currentImage = 0
}else{
currentImage += 1
}
swipeImageView.image = images[currentImage]
case UISwipeGestureRecognizer.Direction.right:
if currentImage == 0 {
currentImage = images.count - 1
}else{
currentImage -= 1
}
swipeImageView.image = images[currentImage]
default:
break
}
}
}
Я получил это code
от это SO-пост. Я делаю что-то не так? Я не знаю, что я делаю не так ...