首页 > 解决方案 > 在子视图内拖动时禁用 UIScrollView 滚动 - Swift

问题描述

为了在我的应用程序中实现图表,我使用了这个库:https ://github.com/AAChartModel/AAChartKit-Swift

我的图表视图位于 UIScrollView 内。当用户在图表视图中拖动值时,我希望我的 UIScrollView 不会同时滚动。

我尝试通过覆盖这些方法来实现这一点:

open override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
    super.touchesBegan(touches, with: event)
    guard let touchPoint = touches.first?.location(in: self) else { return }
}

open override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {
    super.touchesEnded(touches, with: event)
}

但即使我在 AAChartView 扩展中覆盖这些方法,触摸也只能在图表周围识别。

标签: iosswift

解决方案


推荐阅读