使用CALayer创建自定义形状按钮
实现以下目标的最佳方式是什么?
what is the best way to achieve the following.
基本上我想要做的是创建一个难以处理的区域,用户可以触摸该区域并进行后续操作。例如,在图片中,用户点击绿色区域,弹出窗口带有一些选项。同样地,如果可能的话,在披萨切片中会有不同颜色的难以处理的区域或按钮。
Basically what I want to do is to create an "intractable area" where the user can touch and subsequent actions will take place. For example in the picture the user taps the green area a pop is presented with some options. Similarly there would be different colour "intractable areas or buttons" with in that pizza slice, if you may.
我想通过CALayer创建按钮并尝试适合他们在空状态图像的边界,但我不知道如何实现这一点。任何其他想法都很受欢迎。
I was thinking of having buttons created through CALayer and try to fit them with in the bounds of the empty state image, but i don't know how to achieve this. Any other ideas are well appreciated.
我会继承 UIButton
或 UIControl
来制作自定义按钮。然后覆盖 pointInside:withEvent:
以查看触摸事件是否在正确的区域内。
I would subclass UIButton
or UIControl
to make your custom button. Then override pointInside:withEvent:
to see if the touch event is within the correct region.
请参阅以下链接:更多的信息和想法:
See these links for more info and ideas:
- iOS上的非矩形按钮
- 滥用UIView (参见pointInside:withEvent:)
- 如何使用非矩形按钮创建透明窗口?
- 带有非矩形形状的iPhone按钮?
- OBShapedButton
- Non-Rectangular Buttons on iOS
- Abusing UIView (see section on pointInside:withEvent:)
- How to create a transparent window with non-rectangular buttons?
- iPhone button with non-rectangle shape?
- OBShapedButton