0

I have a UIControl subclass on an iPad inside of a UISplitView. Dragging left to right in the control invokes the show master view functionality of the UISplitView. Below is the touch tracking that I do in the control. Is there a way to prevent the dragging from being recognized as a gesture on UISplitView?

override func beginTrackingWithTouch(touch: UITouch, withEvent event: UIEvent?) -> Bool {
    super.beginTrackingWithTouch(touch, withEvent: event)

    shouldMoveHandle = isPointInHandle(touch.locationInView(self))
    return true
}

override func continueTrackingWithTouch(touch: UITouch, withEvent event: UIEvent?) -> Bool {
    super.continueTrackingWithTouch(touch, withEvent: event)

    let lastPoint = touch.locationInView(self)
    if shouldMoveHandle {
        let center = CGPoint(x: bounds.size.width / 2.0, y: bounds.size.height / 2.0)
        angle = 360.0 - angleFromPoints(center, p2: lastPoint )
        handlePosition = pointFromAngle(angle)
        _value = valueFromAngle(angle)
        self.setNeedsDisplay()
    }
    return true
}

override func endTrackingWithTouch(touch: UITouch?, withEvent event: UIEvent?) {
    super.endTrackingWithTouch(touch, withEvent: event)
    shouldMoveHandle = false
    self.sendActionsForControlEvents(UIControlEvents.ValueChanged)
}
Mr Beardsley
  • 3,743
  • 22
  • 28
  • You can try to grab the gesture recogniser of the UISplitView and set it it to fail based on some other recogniser you will have in your UIControl subclass with `requireGestureRecognizerToFail(_:)` Also my advice would be to look into `UIGestureRecognizerDelegate` and `gestureRecognizerShouldBegin(_:)` – tmpz Jan 11 '16 at 08:58
  • 1
    Thank you for your guidance. It turns out I was able to get it to work by overriding the `gestureRecognizerShouldBegin` function and returning false when I got an instance of `UIPanGestureRecognizer` while the user is dragging in the control. Thanks again! – Mr Beardsley Jan 12 '16 at 03:04

0 Answers0