How to add a touch event / or gesture in my overlapping custom text views - swift ios

I couldn’t get it to work with the gesture recognizer in my application.

In viewDidLoadI added these

let orangeIndicatorTap = UITapGestureRecognizer(target: self, action: #selector(self.orangeIndicatorClick(_:)))
    orangeIndicatorTap.numberOfTapsRequired = 1
    orangeIndicatorTap.delegate = self

    conceptMiddleOrangeIndicator.tag = 1
    conceptMiddleOrangeIndicator.isUserInteractionEnabled = true
    conceptMiddleOrangeIndicator.addGestureRecognizer(orangeIndicatorTap)

    let greenIndicatorTap = UITapGestureRecognizer(target: self, action: #selector(self.greenIndicatorClick(_:)))
    greenIndicatorTap.numberOfTapsRequired = 1

    conceptMiddleGreenIndicator.isUserInteractionEnabled = true
    conceptMiddleGreenIndicator.addGestureRecognizer(greenIndicatorTap)


    let purpleIndicatorTap = UITapGestureRecognizer(target: self, action: #selector(self.purpleIndicatorClick(_:)))
    greenIndicatorTap.numberOfTapsRequired = 1

    conceptMiddlePurpleColorIndicator.isUserInteractionEnabled = true
    conceptMiddlePurpleColorIndicator.addGestureRecognizer(purpleIndicatorTap)

enter image description here

Is there any other way to add a click event to my overlapping custom uitextviews?

0
source share
2 answers

I fixed it, it was due to an overlay that was not removed correctly.

This seems to be noticeably removed, but the logical overlays have not been removed. This is why the gesture does not work.

Hope this helps someone in the future.

0
source

touchesBegan, , view .

, .

override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
    let touch = touches.first
    if touch.view == yourView_outlet {
    // add your code here
    } else if touch.view == yourView_outlet {
    // add your code here
    }
}
0

All Articles