我想在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)
respondToGesture:
@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
帖子中获得的this。我做错什么了吗?我不知道我在做什么错...