View hierarchy is like this,
- control (UIView)
- container (UIView)
- icon (UILabel)
- label(UILabel)
If I try to add Tap gesture on control, it works perfectly. If I try to addTap gesture on any of the other items, it doesn't work.
isUserInteractionEnabled is enabled for every element. I also called BringToFront for each element.
I also tried to set UIGestureRecognizerDelegate and detect Touch event, it isn't detecting as well.
Any idea?
Here is the code,
func setGesture() {
// self.isUserInteractionEnabled = true
// containerView.isUserInteractionEnabled = true
label.isUserInteractionEnabled = true
// exclamationMark.isUserInteractionEnabled = true
self.bringSubview(toFront: containerView)
containerView.bringSubview(toFront: exclamationMark)
label.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(didTapSavingLabel)))
//exclamationMark.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(didTapExclamationMarkButton)))
//self.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(selfTapped)))
}
@objc func didTapExclamationMarkButton() {
delegate?.didTapExclamationMarkButton()
}
@objc func didTapSavingLabel() {
delegate?.didTapSavingLabel()
}
@objc func selfTapped() {
print("Self Tapped")
}
If i uncomment the Tap gesture on Self, it works well.