我有一个包含圆形渐变的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];
}
上面的代码在我的panGestureRecognizer
的方法中。
发布于 2013-07-09 09:24:49
您可以在该圆形视图的顶部添加另一个UIView
,并将手势应用于该视图。
UIView *gestureView = [[UIView alloc]initWithFrame:CGRectMake(100, 100, 100, 100)];
[gestureView.layer setCornerRadius:gestureView.frame.size.width/2];
这会给你一个圆形的UIView
**.** ,根据你的需要调整大小和位置。
https://stackoverflow.com/questions/17544213
复制相似问题