1
我有一個ImageView
包含一個圓形漸變和panGestureRecognizer
,我想特別限制爲了防止在視圖或白色背景中UISliders
的干擾梯度。限制一個平移手勢識別器到ImageView?
如何才能識別漸變內的觸摸?
截至目前,我使用這個公式與壞的結果:
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
的方法內。
我會試試!謝謝 – Exothug
這不會禁用視圖下方的漸變,即使當我拖出可見漸變的邊界時,仍然會給我顏色。 – Exothug
你想在這裏實現什麼? 你只是想限制觸摸區域或其他任何東西嗎? –