Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jsp/3.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
Cocoa touch iOS:按钮的非方形命中区域_Cocoa Touch_Ios_Button_Uikit - Fatal编程技术网

Cocoa touch iOS:按钮的非方形命中区域

Cocoa touch iOS:按钮的非方形命中区域,cocoa-touch,ios,button,uikit,Cocoa Touch,Ios,Button,Uikit,我需要做一些相互重叠的三角形按钮 虽然UIButton可以将透明图像作为背景,并且uicontrol可以具有自定义视图,但这些按钮的命中区域始终为方形。如何为我的按钮创建三角形区域 我来自FLash背景,所以我通常会为我的视图创建一个hitarea,但我不相信我能在Cocoa中做到这一点 任何提示?您可以通过子类化UIButton并提供自己的: - (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event { // retur

我需要做一些相互重叠的三角形按钮

虽然UIButton可以将透明图像作为背景,并且uicontrol可以具有自定义视图,但这些按钮的命中区域始终为方形。如何为我的按钮创建三角形区域

我来自FLash背景,所以我通常会为我的视图创建一个hitarea,但我不相信我能在Cocoa中做到这一点


任何提示?

您可以通过子类化
UIButton
并提供自己的:

- (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event {
    // return YES if point is inside the receiver’s bounds; otherwise, NO.
}

提供详细信息,例如确认
已在接收器的坐标系中。

谢谢,我将对此进行研究。这里有一篇很好的文章,描述了一个使用alpha图像的解决方案,这是一个有效的解决方案。但是,即使我触摸按钮外的区域,也会调用此方法。这不是不必要的计算吗,尤其是有多个按钮的情况下?