views:

2075

answers:

2

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?

+4  A: 

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, ...
};
monowerker
So could you explain what I'm seeing a bit more? How did you get those values? Why does 0x00000001<<27 become 00001000 00000000 00000000 00000000 for example. I'm glad you solved my problem but I also want to understand what's going on, so I can solve it myself the next time.
klaaspieter
<< is the C left shift operator. It means "return the value obtained by shifting the rh value (0x00000001) the lh number of binary digits to the left. In the case it takes the single bit in the lowest position and shifts it left 27 times to get your answer.
Roger Nolan
urrr, I got my left and right mixed up but I'm sure you get the idea.
Roger Nolan
I did some more research using the on this. People that want to understand this should take a look at: http://irc.essex.ac.uk/www.iota-six.co.uk/c/e5_bitwise_shift_operators.asp or http://en.wikipedia.org/wiki/Bitwise_operation
klaaspieter
A: 

To use the enums you just do bitwise operations:

UIControlEventAllEditingEvents | UIControlEventApplicationReserved | UIControlEventApplicationReserved
Corey Floyd