Ios 在自定义分段控件中拖动时意外调用cancelTracking

Ios 在自定义分段控件中拖动时意外调用cancelTracking,ios,swift,cocoa-touch,uicontrol,segmentedcontrol,Ios,Swift,Cocoa Touch,Uicontrol,Segmentedcontrol,我使用的是来自的自定义分段控件,此外,我希望在滑动/拖动时更改选定的分段,因此我添加了以下功能: override func beginTracking(_ touch: UITouch, with event: UIEvent?) -> Bool { super.beginTracking(touch, with: event) let location = touch.location(in: self) lastTouchLocation = loc

我使用的是来自的自定义分段控件,此外,我希望在滑动/拖动时更改选定的分段,因此我添加了以下功能:

override func beginTracking(_ touch: UITouch, with event: UIEvent?) -> Bool {
    super.beginTracking(touch, with: event)
    
    let location = touch.location(in: self)
    lastTouchLocation = location

    return true
}

override func continueTracking(_ touch: UITouch, with event: UIEvent?) -> 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 <= newX && newX + thumbView.frame.width <= 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 && calculatedIndex != selectedIndex {
        selectedIndex = calculatedIndex!
        sendActions(for: .valueChanged)
    } else {
        displayNewSelectedIndex()
    }
}
override func beginracking(uuch:UITouch,带有事件:UIEvent?)->Bool{
super.beginking(触摸,带有:事件)
让位置=触摸。位置(in:self)
lastTouchLocation=位置
返回真值
}
覆盖函数连续跟踪(uTouch:UITouch,带有事件:UIEvent?->Bool{
super.continueTracking(触摸,带有:事件)
让位置=触摸。位置(in:self)
打印(location.x-lastTouchLocation!.x)
设newX=thumbView.frame.origin.x+(location.x-lastTouchLocation!.x)

如果frame.minX我最近在我的自定义UIControl位于表单上时遇到了这个问题。它在popover上运行良好,但当我将相同的控件置于表单上时,它将中止突然横向拖动的功能,似乎没有任何原因。
取消跟踪
被调用,但事件没有告诉我原因。我发现这与iO有关S13的新方法是通过向下拖动来取消表单。为了修复它,我将此代码添加到扩展UIControl的类中:

override func gestureRecognizerShouldBegin(_ gestureRecognizer: UIGestureRecognizer) -> Bool {
    if gestureRecognizer is UIPanGestureRecognizer {
        return false
    }
    return true
}

伟大的发现,有完全相同的问题!