CaffeineShots
CaffeineShots

Reputation: 2162

TapGestureRecognizer not firing in swift

Hi I'm having no cards to used to fixed this. Here we go.

I have this five imageview this is the declaration of first imageview but basically they have same declaration

 @IBOutlet weak var first: UIImageView!{
        didSet{
            first.tag = 1
            first.addGestureRecognizer(tapGesture())
        }
    }

and Then the tapGesture() method is this

private func tapGesture() -> UITapGestureRecognizer {
    let tapGesture = UITapGestureRecognizer(target: self, action: Selector("iconTapped:"))
    tapGesture.numberOfTapsRequired = 1
    tapGesture.numberOfTouchesRequired = 1
    return tapGesture
}

the action when the imageview is tapped the iconTapped() method is called, this is the code

func iconTapped(sender:UITapGestureRecognizer){
    if let tag = sender.view?.tag{
        processGesture(tag)
    }
}

I have put all imageview userInteractionEnable to true but still not firing. Could anyone help me?

Some factor may or may not help, inside the viewdidload I update constraints and do some animation to imageview, but I'm not adding any subview programmatically

Upvotes: 1

Views: 165

Answers (1)

CaffeineShots
CaffeineShots

Reputation: 2162

after trying so many things, I look on my view hierarchy and figure out that the parent view where my UIImageView rest userInteractionEnable is set to false(unchecked) in storyboard.

in this case the parentview is my superview, to fixed that I need to add this in viewDidLoad()

self.view.userInteractionEnabled = true

or

click the parentView in storyboard and in attributes inspector check the User Interaction Enable.

ps. sorry for silly mistake but I'll keep this question posted there might be other encountering same problem.

Upvotes: 4

Related Questions