From aad596b96bb9a78d417afc3fd22646973fd3f209 Mon Sep 17 00:00:00 2001 From: Andreas Ganske Date: Fri, 8 Jun 2018 00:13:22 +0200 Subject: [PATCH] Do not respond to touch if point is outside the cropped circle --- RSColorPicker/ColorPickerClasses/RSColorPickerView.m | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/RSColorPicker/ColorPickerClasses/RSColorPickerView.m b/RSColorPicker/ColorPickerClasses/RSColorPickerView.m index db012e2..503d7ab 100755 --- a/RSColorPicker/ColorPickerClasses/RSColorPickerView.m +++ b/RSColorPicker/ColorPickerClasses/RSColorPickerView.m @@ -403,6 +403,17 @@ - (RSColorPickerState *)stateForPoint:(CGPoint)point { return newState; } +- (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event { + if (!self.cropToCircle) { + return [super pointInside:point withEvent:event]; + } + + CGFloat X = point.x - CGRectGetMidX(self.bounds); + CGFloat Y = point.y - CGRectGetMidY(self.bounds); + CGFloat r = sqrt(pow(X, 2) + pow(Y, 2)); + return [super pointInside:point withEvent:event] && r < self.paletteDiameter / 2; +} + - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { if (self.showLoupe) {