禁用为UIControl子类发送手势

时间:2016-01-11 05:36:19

标签: ios swift gesture uicontrol uisplitview

我在UISplitView的iPad上有一个UIControl子类。在控件中从左向右拖动会调用UISplitView的show master视图功能。以下是我在控件中执行的触摸跟踪。有没有办法阻止拖动被识别为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)
}

0 个答案:

没有答案