title: How do I check multiple UIView subviews displayed on top of each other for a touch event inside a bezier path?
body: <p>I've written some code that generates wedges of a wheel in UIViews, stores these UIViews in an array, and displays these UIViews on top of one another, inside of a container UIView. This basically draws a segmented wheel.</p>
  
  <p>What I now want is for every UIView to receive touch events individually within it's defined bezier path, and return a unique identifier. This would in practice mean that every wedge of the wheel is an individual button.</p>
  
  <p>The problem I have right now is that only the last UIView that was added to the array responds to a single touch event (I have it set up to print the touch location within the bezier path right now), after which the UIView added before that responds to a single touch event, until I've cycled through all the wedges/UIViews and none respond to touch events anymore.</p>
  
  <p>Here's the class that draws the wedges; I've tried implementing some methods that should allow touch events to be transferred to other UIViews at the end of the code, but I can't get it to work.</p>
  
  <pre><code>import UIKit
  
  class WedgeDraw: UIView {
  
  var wedgeNumber:CGFloat = 4
  var wedgeLocation: CGFloat = 2
  
  var wedgeIdentifier = 0
  var wedgePath = UIBezierPath()
  var touchPosition = CGPoint()
  
  
  override func draw(_ rect: CGRect) {
  
      let startAngle = (360 / wedgeNumber - 360) * (wedgeLocation - 1) * CGFloat.pi / 180
      let endangle = (360 / wedgeNumber - 360) * wedgeLocation * CGFloat.pi / 180
  
  
      let center = CGPoint(x: self.bounds.midX, y: self.bounds.midY)
  
      let outerRadius = self.bounds.midX - 3
      let innerRadius = self.bounds.width / 8
  
      //defines end points of simulated Bezier archs as a CGpoint
      let endPointInner = UIBezierPath(arcCenter: center, radius: innerRadius, startAngle: startAngle, endAngle: endangle, clockwise: false).currentPoint
      let endPointOuterCounterclockwise = UIBezierPath(arcCenter: center, radius: outerRadius, startAngle: endangle, endAngle: startAngle, clockwise: true).currentPoint
  
      //defines bezier arch curves
      let outerWedgeCurvePath = UIBezierPath(arcCenter: center, radius: outerRadius, startAngle: startAngle, endAngle: endangle, clockwise: true)
      let innerWedgeCurvePath = UIBezierPath(arcCenter: center, radius: innerRadius, startAngle: endangle, endAngle: startAngle, clockwise: false)
  
      //draw line path
  
      wedgePath.append(outerWedgeCurvePath)
      wedgePath.addLine(to: endPointInner)
      wedgePath.append(innerWedgeCurvePath)
      wedgePath.addLine(to: endPointOuterCounterclockwise)
  
      //sets stroke and color properties and draws the bezierpath.
  
      UIColor.black.setStroke()
      UIColor.white.setFill()
      wedgePath.lineWidth = 3
      wedgePath.stroke()
      wedgePath.fill()
  
  
  }
  
  override func hitTest(_ point: CGPoint, with event: UIEvent?) -&gt; UIView? {
      let view = super.hitTest(point, with: event)
      if wedgePath.contains(touchPosition) {
          return nil
      } else {
          return view
      }
  }
  
  override func touchesEnded(_ touches: Set&lt;UITouch&gt;, with event: UIEvent?) {
  
      if let touch = touches.first {
          touchPosition = touch.location(in: self)
  
          if wedgePath.contains(touchPosition){
              print(touchPosition)
              print(isUserInteractionEnabled)
          } else {
  
          }
      }
  }
  }
  </code></pre>
  
  <p>Here's the Viewcontroller code that creates the array and draws the wheel:</p>
  
  <pre><code>import UIKit
  
  class ViewController: UIViewController {
  
  @IBOutlet weak var boardContainer: UIView!
  
  @IBAction func checkButton(_ sender: UIButton) {
  
  }
  
  var wedgeViewConstructorArray = [WedgeDraw]()
  
  
  override func viewDidLoad() {
      super.viewDidLoad()
  
      //creates array of UNIQUE wedgedraw objects
      for _ in 1...6 {
          wedgeViewConstructorArray.append(WedgeDraw())
      }
      drawBoard()
  }
  
  func drawBoard() {
  
      for i in 0..&lt;wedgeViewConstructorArray.count {
          wedgeViewConstructorArray[i].wedgeIdentifier = i
  
          wedgeViewConstructorArray[i].frame = CGRect(x: 0, y: 0, width: boardContainer.frame.width, height: boardContainer.frame.height)
  
          wedgeViewConstructorArray[i].wedgeNumber = CGFloat(wedgeViewConstructorArray.count)
          wedgeViewConstructorArray[i].wedgeLocation = CGFloat(i + wedgeViewConstructorArray.count + 1)
          wedgeViewConstructorArray[i].backgroundColor = UIColor.clear
  
          boardContainer.addSubview(wedgeViewConstructorArray[i])
      }
  }  
  }
  </code></pre>
  
  <p>This is what the rendering of the wheel looks like, and the view hierarchy:</p>
  
  <p><a href="https://i.stack.imgur.com/rYWXE.png" rel="nofollow noreferrer">Wheelimage</a></p>
  
  <p>I'm still very new to swift and coding in general, and I am pretty happy to get where I am, but I'm really stuck now, and have no real idea how to proceed. I hope I've managed to make it clear what my problem is!
  Thanks in advance!</p>