Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Touch exclusion area added #79

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions RSColorPicker/ColorPickerClasses/RSColorPickerView.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,14 @@ IB_DESIGNABLE
*/
@property (readonly) CGFloat paddingDistance;


/**
*this specifies the area that is excluded from center
*/
@property (readwrite) CGFloat activeAreaFromEdge;



/**
* Specifies if the loupe should be drawn or not.
* Default: YES (show).
Expand Down
19 changes: 16 additions & 3 deletions RSColorPicker/ColorPickerClasses/RSColorPickerView.m
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#import "RSGenerateOperation.h"
#import "RSSelectionLayer.h"

#define kSelectionViewSize 22
#define kSelectionViewSize 16

@interface RSColorPickerView () {
struct {
Expand All @@ -33,6 +33,14 @@ @interface RSColorPickerView () {
@property (nonatomic) UIBezierPath *activeAreaShape;



/**
* A path which represents the area where user cant pick color, calculated from excludedAreaFromCenter
*/
@property (nonatomic) UIBezierPath *noActiveAreaShape;



/**
* The layer which contains just the currently selected color
* within the -selectionLayer.
Expand Down Expand Up @@ -168,7 +176,8 @@ - (void)initRoutine {

self.contentsLayer.masksToBounds = YES;
self.cropToCircle = NO;
self.selectionColor = [UIColor whiteColor];
self.selectionColor = [UIColor blueColor];
self.activeAreaFromEdge= 0.0f;
}

- (void)resizeOrRescale {
Expand Down Expand Up @@ -232,12 +241,16 @@ - (void)generateBezierPaths {
[CATransaction setDisableActions:YES];

CGRect activeAreaFrame = CGRectInset(self.bounds, self.paddingDistance, self.paddingDistance);
CGRect nonActiveAreaFrame = CGRectInset(self.bounds, self.paddingDistance+self.activeAreaFromEdge, self.paddingDistance+self.activeAreaFromEdge);

if (self.cropToCircle) {
self.contentsLayer.cornerRadius = self.paletteDiameter / 2.0;
self.activeAreaShape = [UIBezierPath bezierPathWithOvalInRect:activeAreaFrame];
self.noActiveAreaShape= [UIBezierPath bezierPathWithOvalInRect:nonActiveAreaFrame];
} else {
self.contentsLayer.cornerRadius = 0.0;
self.activeAreaShape = [UIBezierPath bezierPathWithRect:activeAreaFrame];
self.noActiveAreaShape= [UIBezierPath bezierPathWithOvalInRect:nonActiveAreaFrame];
}

[CATransaction commit];
Expand Down Expand Up @@ -352,7 +365,7 @@ - (CGFloat)paletteDiameter {
#pragma mark - Touch Events -

- (CGPoint)validPointForTouch:(CGPoint)touchPoint {
if ([self.activeAreaShape containsPoint:touchPoint]) {
if ([self.activeAreaShape containsPoint:touchPoint] && ![self.noActiveAreaShape containsPoint:touchPoint]) {
return touchPoint;
}

Expand Down
1 change: 1 addition & 0 deletions RSColorPicker/TestColorViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ - (void)viewDidLoad {
// On/off circle or square
UISwitch *circleSwitch = [[UISwitch alloc] initWithFrame:CGRectMake(10, 340, 0, 0)];
[circleSwitch setOn:_colorPicker.cropToCircle];
_colorPicker.activeAreaFromEdge= 60;
[circleSwitch addTarget:self action:@selector(circleSwitchAction:) forControlEvents:UIControlEventValueChanged];
[self.view addSubview:circleSwitch];

Expand Down