我有ImageView
包含圆形渐变和panGestureRecognizer
,我想专门限制渐变,以防止干扰视图或白色背景中的UISliders
。< / p>
我如何只识别渐变内的触摸?
截至目前,我正在使用这个等式,结果不好:
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];
}
上面的代码在我的panGestureRecognizer
方法中。
答案 0 :(得分:0)
您可以在该圆形视图的顶部添加另一个UIView
,并将手势应用于该视图。
UIView *gestureView = [[UIView alloc]initWithFrame:CGRectMake(100, 100, 100, 100)];
[gestureView.layer setCornerRadius:gestureView.frame.size.width/2];
这会给您一个循环UIView
。
根据需要调整大小和位置。