gpt4 book ai didi

ios - 在 iOS 中创建具有不同可触摸区域的圆圈

转载 作者:行者123 更新时间:2023-11-29 04:49:30 30 4
gpt4 key购买 nike

我想创建一个圆圈。这个圆圈将有四个部分,我想让每个部分都是可触摸的。

例如,如果我按第 1 部分执行操作 A,按第 2 部分执行操作 B,等等

我想我可以使用 openGL 绘制圆圈或使用准备好的图像。

如何做到这一点?

最佳答案

为什么要用 OpenGL 画圆?

您可以子类化 UIView 并在 -drawRect: 中进行绘图,并使用 UIView 的点击检测来确定触摸位置-touchesBegan:...

如果您想要更轻量级的东西,您可以使用 CALayer 及其 -hitTest: 方法实现相同的功能。

这是一个绘图示例

@implementation MYView

- (void)drawRect:(CGRect)rect {
[[UIColor blackColor] set];
UIBezierPath *circle = [UIBezierPath bezierPathWithOvalInRect:self.bounds];
[circle fill];
}

@end

关于ios - 在 iOS 中创建具有不同可触摸区域的圆圈,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9100156/

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