Skip to content

Commit

Permalink
Simplify those
Browse files Browse the repository at this point in the history
  • Loading branch information
danielgindi committed May 7, 2015
1 parent e056480 commit 2f470c5
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 64 deletions.
58 changes: 11 additions & 47 deletions Charts/Classes/Charts/BarLineChartViewBase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,13 @@ public class BarLineChartViewBase: ChartViewBase, UIGestureRecognizerDelegate
_panGestureRecognizer.delegate = self;

self.addGestureRecognizer(_tapGestureRecognizer);
if (_doubleTapToZoomEnabled)
{
self.addGestureRecognizer(_doubleTapGestureRecognizer);
}
updateScaleGestureRecognizers();
self.addGestureRecognizer(_doubleTapGestureRecognizer);
self.addGestureRecognizer(_pinchGestureRecognizer);
self.addGestureRecognizer(_panGestureRecognizer);

_doubleTapGestureRecognizer.enabled = _doubleTapToZoomEnabled;
_pinchGestureRecognizer.enabled = _pinchZoomEnabled || _scaleXEnabled || _scaleYEnabled;
_panGestureRecognizer.enabled = _dragEnabled;
}

public override func drawRect(rect: CGRect)
Expand Down Expand Up @@ -974,7 +975,7 @@ public class BarLineChartViewBase: ChartViewBase, UIGestureRecognizerDelegate
{
_scaleXEnabled = enabled;
_scaleYEnabled = enabled;
updateScaleGestureRecognizers();
_pinchGestureRecognizer.enabled = _pinchZoomEnabled || _scaleXEnabled || _scaleYEnabled;
}
}

Expand All @@ -989,7 +990,7 @@ public class BarLineChartViewBase: ChartViewBase, UIGestureRecognizerDelegate
if (_scaleXEnabled != newValue)
{
_scaleXEnabled = newValue;
updateScaleGestureRecognizers();
_pinchGestureRecognizer.enabled = _pinchZoomEnabled || _scaleXEnabled || _scaleYEnabled;
}
}
}
Expand All @@ -1005,7 +1006,7 @@ public class BarLineChartViewBase: ChartViewBase, UIGestureRecognizerDelegate
if (_scaleYEnabled != newValue)
{
_scaleYEnabled = newValue;
updateScaleGestureRecognizers();
_pinchGestureRecognizer.enabled = _pinchZoomEnabled || _scaleXEnabled || _scaleYEnabled;
}
}
}
Expand All @@ -1025,24 +1026,7 @@ public class BarLineChartViewBase: ChartViewBase, UIGestureRecognizerDelegate
if (_doubleTapToZoomEnabled != newValue)
{
_doubleTapToZoomEnabled = newValue;
if (_doubleTapToZoomEnabled)
{
self.addGestureRecognizer(_doubleTapGestureRecognizer);
}
else
{
if (self.gestureRecognizers != nil)
{
for (var i = 0; i < self.gestureRecognizers!.count; i++)
{
if (self.gestureRecognizers?[i] === _doubleTapGestureRecognizer)
{
self.gestureRecognizers!.removeAtIndex(i);
break;
}
}
}
}
_doubleTapGestureRecognizer.enabled = _doubleTapToZoomEnabled;
}
}
}
Expand Down Expand Up @@ -1329,29 +1313,9 @@ public class BarLineChartViewBase: ChartViewBase, UIGestureRecognizerDelegate
if (_pinchZoomEnabled != newValue)
{
_pinchZoomEnabled = newValue;
updateScaleGestureRecognizers();
}
}
}

private func updateScaleGestureRecognizers()
{
if (self.gestureRecognizers != nil)
{
for (var i = 0; i < self.gestureRecognizers!.count; i++)
{
if (self.gestureRecognizers![i] === _pinchGestureRecognizer)
{
self.gestureRecognizers!.removeAtIndex(i);
break;
}
_pinchGestureRecognizer.enabled = _pinchZoomEnabled || _scaleXEnabled || _scaleYEnabled;
}
}
if (_pinchZoomEnabled || _scaleXEnabled || _scaleYEnabled)
{
self.addGestureRecognizer(_pinchGestureRecognizer);
}
}

/// returns true if pinch-zoom is enabled, false if not
Expand Down
21 changes: 4 additions & 17 deletions Charts/Classes/Charts/PieRadarChartViewBase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,9 @@ public class PieRadarChartViewBase: ChartViewBase
_rotationGestureRecognizer = UIRotationGestureRecognizer(target: self, action: Selector("rotationGestureRecognized:"));

self.addGestureRecognizer(_tapGestureRecognizer);
self.addGestureRecognizer(_rotationGestureRecognizer);

if (rotationWithTwoFingers)
{
self.addGestureRecognizer(_rotationGestureRecognizer);
}
_rotationGestureRecognizer.enabled = rotationWithTwoFingers;
}

internal override func calcMinMax()
Expand Down Expand Up @@ -369,19 +367,8 @@ public class PieRadarChartViewBase: ChartViewBase
}
set
{
if (newValue != _rotationWithTwoFingers)
{
_rotationWithTwoFingers = newValue;

if (_rotationWithTwoFingers)
{
self.addGestureRecognizer(_rotationGestureRecognizer);
}
else
{
self.removeGestureRecognizer(_rotationGestureRecognizer);
}
}
_rotationWithTwoFingers = newValue;
_rotationGestureRecognizer.enabled = _rotationWithTwoFingers;
}
}
Expand Down

0 comments on commit 2f470c5

Please sign in to comment.