阿神2017-05-02 09:21:11
The UIRectCornerTopLeft and UIRectCornerTopRight shown in your code are actually not enumerations, but 按位掩码(bitmask)
, and their definition is as follows:
typedef NS_OPTIONS(NSUInteger, UIRectCorner) {
UIRectCornerTopLeft = 1 << 0,
UIRectCornerTopRight = 1 << 1,
UIRectCornerBottomLeft = 1 << 2,
UIRectCornerBottomRight = 1 << 3,
UIRectCornerAllCorners = ~0UL
};
The syntax of a bitwise mask (NS_OPTIONS) is the same as an enumeration (NS_ENUM), but the compiler will combine its values |
through a bitmask.
For example, for the NS_OPTIONS of UIRectCorner above, according to your code, what you pass in is UIRectCornerTopLeft | UIRectCornerTopRight
, then the processing code is roughly as follows:
UIRectCorner myRectCornerOptions = UIRectCornerTopLeft | UIRectCornerTopRight; // 你在方法里接收到值应该是这个。
// 对传入的 NS_OPTIONS 的处理逻辑:
if (myRectCornerOptions & UIRectCornerTopLeft) {
// 包含了 UIRectCornerTopLeft。
} else {
// 未包含 UIRectCornerTopLeft。
}
if (myRectCornerOptions & UIRectCornerTopRight) {
// 包含了 UIRectCornerTopRight。
} else {
// 未包含 UIRectCornerTopRight。
}