Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/111.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 将平移手势识别器限制为ImageView?_Ios_Objective C_Imageview_Bounds - Fatal编程技术网

Ios 将平移手势识别器限制为ImageView?

Ios 将平移手势识别器限制为ImageView?,ios,objective-c,imageview,bounds,Ios,Objective C,Imageview,Bounds,我有一个ImageView包含一个圆形渐变和一个pangesture识别器,我想专门限制渐变,以防止干扰视图中的UISliders或白色背景 如何仅识别渐变中的接触 到目前为止,我使用的这个等式结果很糟糕: CGPoint lastPoint = [sender locationOfTouch: sender.numberOfTouches - 1 inView: gradientView]; CGPoint center = CGPointMake((size.

我有一个
ImageView
包含一个圆形渐变和一个
pangesture识别器
,我想专门限制渐变,以防止干扰视图中的
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];

        }
if((lastPoint.x-center.x)+(lastPoint.y-center.y)/2

上面的代码在我的
pangestureerecognizer
方法中。

您可以在该圆形视图的顶部添加另一个
ui视图
,并对该视图应用手势

UIView *gestureView = [[UIView alloc]initWithFrame:CGRectMake(100, 100, 100, 100)];
[gestureView.layer setCornerRadius:gestureView.frame.size.width/2];
这将为您提供一个循环的
ui视图

根据您的需要调整大小和位置。

这不会禁用视图下方的渐变,即使在可见渐变边界之外拖动,也会为我提供颜色。您希望在这里实现什么?你只是想限制触摸区域还是其他什么?我计划限制手势识别器识别的区域,以便只使用渐变的可见部分