首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >是否将平移手势识别器限制为ImageView?

是否将平移手势识别器限制为ImageView?
EN

Stack Overflow用户
提问于 2013-07-09 09:07:19
回答 1查看 220关注 0票数 1

我有一个包含圆形渐变的ImageView和一个panGestureRecognizer,我希望将其限制为特定的渐变,以防止与视图中的UISliders或白色背景的干扰。

如何才能仅识别渐变中的触点?

到目前为止,我正在使用这个等式,但结果很糟糕:

代码语言:javascript
运行
AI代码解释
复制
        CGPoint lastPoint = [sender locationOfTouch: sender.numberOfTouches - 1 inView: gradientView];
        CGPoint center = CGPointMake((size.width/2), (size.height /2));

这些变量用于指示渐变的中心。这就是方程式:

代码语言:javascript
运行
AI代码解释
复制
        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的方法中。

EN

回答 1

Stack Overflow用户

发布于 2013-07-09 09:24:49

您可以在该圆形视图的顶部添加另一个UIView,并将手势应用于该视图。

代码语言:javascript
运行
AI代码解释
复制
UIView *gestureView = [[UIView alloc]initWithFrame:CGRectMake(100, 100, 100, 100)];
[gestureView.layer setCornerRadius:gestureView.frame.size.width/2];

这会给你一个圆形的UIView**.** ,根据你的需要调整大小和位置。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/17544213

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档