0

I am using third party Color picker wheel (ISColorWheel- https://github.com/justinmeiners/ios-color-wheel) to pick a color and display it on screen. I need to restrict selecting blue color if particular button is enabled.

enter image description here

When i see the color picker library class, they have implemented following code to restrict the Knob view to move around the color picker.

 - (void)setTouchPoint:(CGPoint)point
{
    CGFloat width = self.bounds.size.width;
    CGFloat height = self.bounds.size.height;

    CGPoint center = CGPointMake(width / 2.0, height / 2.0);

    // Check if the touch is outside the wheel
    if (ISColorWheel_PointDistance(center, point) < _radius)
    {
        //NSLog(@"Distance is %f and Radius is %f",ISColorWheel_PointDistance(center, point),_radius);
        _touchPoint = point;
    }
    else
    {
        // If so we need to create a drection vector and calculate the constrained point
        CGPoint vec = CGPointMake(point.x - center.x, point.y - center.y);

        float extents = sqrtf((vec.x * vec.x) + (vec.y * vec.y));

        vec.x /= extents;
        vec.y /= extents;

        _touchPoint = CGPointMake(center.x + vec.x * _radius, center.y + vec.y * _radius);
        NSLog(@"Touch Point is %f %f",_touchPoint.x,_touchPoint.y);
    }

    [self updateKnob];
}

The above code restrict the user to move knobView away from the circle. In my case i need to restrict the user not to select Blue color of ColorPicker. How can i implement it. How to find the trajectory of Blue color.

iPhone Guy
  • 1,285
  • 3
  • 23
  • 34

1 Answers1

1

You should define a triangle that defines the color blue as you see it (How much green dose it contain in one side how much purple on the other) then look for you Point inside that triangle. One way to do it is here: https://stackoverflow.com/a/9755252/1870192

Community
  • 1
  • 1
Boaz Saragossi
  • 958
  • 10
  • 32