我有一个ImageView
包含圆形渐变和一个panGestureRecognizer
我想专门限制渐变以防止干扰UISliders
视图或白色背景。
我如何只识别渐变内的触摸?
截至目前,我正在使用这个等式,结果很糟糕:
CGPoint lastPoint = [sender locationOfTouch: sender.numberOfTouches - 1 inView: gradientView];
CGPoint center = CGPointMake((size.width/2), (size.height /2));
这些变量用于指示梯度的中心。这是等式:
if((lastPoint.x - center.x) + (lastPoint.y - center.y)/2 < radius)
{
UIColor *color = [UIColor colorWithHue: angle / (M_PI * 2.0) saturation:saturationSlider.value brightness:hellSlider.value alpha:alphaSlider.value];
if ([color getRed: &r green: &g blue:&b alpha: &a])
{
NSLog(@"Color value - R : %g G : %g : B %g", r*255, g*255, b*255);
}
float red = r;
float green = g;
float blue = b;
rText.text = [NSString stringWithFormat:@"%.0f",rSlider.value];
gText.text = [NSString stringWithFormat:@"%.0f",green*255];
bText.text = [NSString stringWithFormat:@"%.0f",blue*255];
colorView.backgroundColor = [UIColor colorWithRed:(rText.text.floatValue/255) green:(gText.text.floatValue/255) blue:(bText.text.floatValue/255) alpha:alphaSlider.value];
rSlider.value = red*255;
gSlider.value = green*255;
bSlider.value = blue*255;
alphaText.text = [NSString stringWithFormat:@"%.2f",alphaSlider.value];
brightnessText.text = [NSString stringWithFormat:@"%.2f",hellSlider.value];
saturationText.text = [NSString stringWithFormat:@"%.2f",saturationSlider.value];
}
上面的代码在 mypanGestureRecognizer
的方法中。