gpt4 book ai didi

ios - 创建可点击的 CGPath

转载 作者:行者123 更新时间:2023-11-29 03:11:59 27 4
gpt4 key购买 nike

我有一个 UIView,其中包含一个带有不规则大小切片的“饼图”,我需要它们是可点击的区域。通过大量的反复试验,我写了一个方法来制作馅饼,但现在我不知道如何将这些切片分成区域。目前这个方法返回 void 所以我需要修改以返回一些东西,比如 CGPath?我想我真正感到困惑的地方是如何将我拥有的东西放入 CGPath 并返回它。有什么建议么?谢谢!

-(void)addClickableRegion:(float)beginDegrees to:(float)endDegrees withContext:(CGContextRef)ctx withRadiusOf:(int)rad{
int x = self.bounds.size.height / 2;
int y = self.bounds.size.width / 2;

float red = (arc4random() % 255)/255.0;
float green = (arc4random() % 255)/255.0;
float blue = (arc4random() % 255)/255.0;

CGContextMoveToPoint(ctx, x, y);
CGContextAddArc(ctx, x, y, rad, (beginDegrees) * M_PI/180.0, (endDegrees) * M_PI/180.0, 0);

CGContextSetRGBFillColor(ctx, red, green, blue, 1.0);

CGContextFillPath(ctx);
CGContextClosePath(ctx);
}

最佳答案

您已经在创建路径,您只是在上下文中创建它们,而不是创建它们然后将它们添加到上下文中。你不需要那样做。您可以使用 CGPathCreateMutableCGPathAddArcCGContextAddPath

您还可以通过 bezierPathWithCGPath: 或直接使用 UIBezierPath(然后从中获取 CGPath)。

而且,一旦您有了贝塞尔曲线路径,您就可以在它们上调用 containsPoint: 来进行测试触摸。

关于ios - 创建可点击的 CGPath,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22158907/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com