diff --git a/README.md b/README.md index 3b79a2c7d..188d5fc86 100644 --- a/README.md +++ b/README.md @@ -136,7 +136,11 @@ class MyViewController: UIViewController, ChartDelegate { } func didFinishTouchingChart(chart: Chart) { - // Do something when finished + // Do something when finished (only called after the user swipes out of the chart either on the right or the left side) + } + + func didEndTouchingChart(chart: Chart) { + // Do something when the user ends touching the chart } } ``` @@ -196,6 +200,7 @@ There is no built-in method to update a chart. To accomplish this: * `delegate`: the delegate for listening to touch events. * `highlightLineColor`: color of the highlight line. * `highlightLineWidth`: width of the highlight line. +* `shouldAutoHideHighlightLine`: automatically hide the highlightLine after we've ended touching the chart. * `gridColor`: the grid color. * `labelColor`: the color of the labels. * `labelFont`: the font used for the labels. diff --git a/Source/Chart.swift b/Source/Chart.swift index 1302f9fd1..632a98769 100644 --- a/Source/Chart.swift +++ b/Source/Chart.swift @@ -167,6 +167,11 @@ open class Chart: UIControl { Width for the highlight line. */ open var highlightLineWidth: CGFloat = 0.5 + + /** + Wether we should automatically hide the highlightLine after touches have ended. + */ + open var autoHideHighlightLine: Bool = false /** Alpha component for the area's color. @@ -643,6 +648,8 @@ open class Chart: UIControl { fileprivate func drawHighlightLineFromLeftPosition(_ left: CGFloat) { if let shapeLayer = highlightShapeLayer { + shapeLayer.isHidden = false + // Use line already created let path = CGMutablePath() @@ -712,6 +719,7 @@ open class Chart: UIControl { override open func touchesEnded(_ touches: Set, with event: UIEvent?) { handleTouchEvents(touches, event: event) + highlightShapeLayer?.isHidden = autoHideHighlightLine delegate?.didEndTouchingChart(self) } @@ -790,4 +798,4 @@ open class Chart: UIControl { let dy2 = level - p2.y return (x: (p2.x * dy1 - p1.x * dy2) / (dy1 - dy2), y: level) } -} +} \ No newline at end of file