视图未检测到滑动图像库的手势识别器

问题描述 投票:0回答:1

我想在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。我做错什么了吗?我不知道我在做什么错...

ios swift uiimage uigesturerecognizer
1个回答
0
投票

点击图像视图,然后转到属性检查器,并确保已启用已启用用户交互]

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.