2015-11-08 73 views
0

我正在使用第三方颜色选取器轮(ISColorWheel- https://github.com/justinmeiners/ios-color-wheel)选取颜色并将其显示在屏幕上。如果启用特定按钮,我需要限制选择蓝色。在ColorPicker UIView上限制触摸 - iOS

enter image description here

当我看到拾色器库类,他们已经实施了下面的代码来限制旋钮以围绕拾色器移动。

- (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]; 
} 

上述代码限制用户将knobView从圆中移开。在我的情况下,我需要限制用户不要选择ColorPicker的蓝色。我如何实现它。如何找到蓝色的运动轨迹。

回答

1

你应该定义一个三角形,它定义了你看到它的颜色为蓝色(在一面含有多少绿色剂量,在另一面含有多少紫色),然后寻找你指向该三角形内的点。一种方法是:https://stackoverflow.com/a/9755252/1870192