理解 Objective c 枚举声明

发布于 2024-07-19 05:04:35 字数 763 浏览 1 评论 0原文

来自 iPhone UIControl

UIControlEventAllTouchEvents      = 0x00000FFF,
UIControlEventAllEditingEvents    = 0x000F0000,
UIControlEventApplicationReserved = 0x0F000000,
UIControlEventSystemReserved      = 0xF0000000,
UIControlEventAllEvents           = 0xFFFFFFFF

现在我假设 UIControlEventApplication 是我可以用来指定自定义控件事件的“范围”,但我不知道如何正确执行它。 仅当我分配 0xF0000000 时,控制事件才会正确触发。 如果我分配其他任何内容(0xF0000001),控制事件就会在不应该的情况下触发。

一些澄清:

enum {
    UIBPMPickerControlEventBeginUpdate = 0x0F000000,
    UIBPMPickerControlEventEndUpdate = // Which value do I use here?

};

我对它是一个范围的假设是基于文档。 其中说:

我这么认为是因为文档说:可供应用程序使用的一系列控制事件值。

谁能帮助我理解 UIControl 中使用的枚举声明的类型?

From iPhone UIControl

UIControlEventAllTouchEvents      = 0x00000FFF,
UIControlEventAllEditingEvents    = 0x000F0000,
UIControlEventApplicationReserved = 0x0F000000,
UIControlEventSystemReserved      = 0xF0000000,
UIControlEventAllEvents           = 0xFFFFFFFF

Now I assume the UIControlEventApplication is the 'range' I can use to specify custom control events, but I have no idea how to do it properly. Only if I assign 0xF0000000 the control event will correctly fire. If I assign anything else (0xF0000001) the control event fires when it's not supposed to.

Some clarification:

enum {
    UIBPMPickerControlEventBeginUpdate = 0x0F000000,
    UIBPMPickerControlEventEndUpdate = // Which value do I use here?

};

My assumption of it being a range is based on the docs. Which say:

I assume this because the docs say: A range of control-event values available for application use.

Could anyone help me understand the type of enum declaration used in UIControl?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

我认为 0x0F000000 是您可以用来创建自己的控制事件的 4 位。

0x0F000000 = 00001111 00000000 00000000 00000000

因此,以下任意组合:

0x00000001<<27 = 00001000 00000000 00000000 00000000
0x00000001<<26 = 00000100 00000000 00000000 00000000
0x00000001<<25 = 00000010 00000000 00000000 00000000
0x00000001<<24 = 00000001 00000000 00000000 00000000

您当然可以将这些组合在一起以创建新的:

0x00000001<<24 | 0x00000001<<25 = 00000011 00000000 00000000 00000000

因此在您的示例中:

enum {
    UIBPMPickerControlEventBeginUpdate = 0x00000001<<24,
    UIBPMPickerControlEventEndUpdate = 0x00000001<<25, ...
};

I would think 0x0F000000 is the 4 bits you have at your disposal for creating your own control events.

0x0F000000 = 00001111 00000000 00000000 00000000

So any combination of:

0x00000001<<27 = 00001000 00000000 00000000 00000000
0x00000001<<26 = 00000100 00000000 00000000 00000000
0x00000001<<25 = 00000010 00000000 00000000 00000000
0x00000001<<24 = 00000001 00000000 00000000 00000000

You can of course OR these together to create new ones:

0x00000001<<24 | 0x00000001<<25 = 00000011 00000000 00000000 00000000

So in your example:

enum {
    UIBPMPickerControlEventBeginUpdate = 0x00000001<<24,
    UIBPMPickerControlEventEndUpdate = 0x00000001<<25, ...
};
天赋异禀 2024-07-26 05:04:35

要使用枚举,您只需执行按位运算:

UIControlEventAllEditingEvents | UIControlEventApplicationReserved | UIControlEventApplicationReserved

To use the enums you just do bitwise operations:

UIControlEventAllEditingEvents | UIControlEventApplicationReserved | UIControlEventApplicationReserved
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文