title: cancelTracking called unexpectedly when dragging in customized segmented control
body: <p>I'm using the customized segmented control from <a href="http://www.appdesignvault.com/custom-segmented-control-swift-tutorial/" rel="nofollow noreferrer">this tutorial</a>, in addition, I would like the selected segment to be changed on a swipe/drag, so I added these functions:</p>
  <pre><code>override func beginTracking(_ touch: UITouch, with event: UIEvent?) -&gt; Bool {
      super.beginTracking(touch, with: event)
      
      let location = touch.location(in: self)
      lastTouchLocation = location
  
      return true
  }
  
  override func continueTracking(_ touch: UITouch, with event: UIEvent?) -&gt; Bool {
      super.continueTracking(touch, with: event)
      
      let location = touch.location(in: self)
      print(location.x - lastTouchLocation!.x)
      
      let newX = thumbView.frame.origin.x + (location.x - lastTouchLocation!.x)
      if frame.minX &lt;= newX &amp;&amp; newX + thumbView.frame.width &lt;= frame.maxX {
          thumbView.frame.origin.x = newX
      }
      lastTouchLocation = location
      
      return true
  }
  
  override func endTracking(_ touch: UITouch?, with event: UIEvent?) {
      super.endTracking(touch, with: event)
      
      let location = touch != nil ? touch!.location(in: self) : lastTouchLocation!
      
      var calculatedIndex : Int?
      for (index, item) in labels.enumerated() {
          if item.frame.contains(location) {
              calculatedIndex = index
          }
      }
      
      if calculatedIndex != nil &amp;&amp; calculatedIndex != selectedIndex {
          selectedIndex = calculatedIndex!
          sendActions(for: .valueChanged)
      } else {
          displayNewSelectedIndex()
      }
  }
  </code></pre>
  <p>I've embedded the control in a UIView container, somehow the touch gets canceled when I drag the thumb view for a short distance</p>
  <p><a href="https://i.stack.imgur.com/4NyUs.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/4NyUs.png" alt="enter image description here" /></a></p>
  <p>Could this be a problem with the view container, and how can I fix this?</p>
  <p>Thank you if you've read the whole thing.</p>