[英]What to pass as a NULL value for the options parameter of [NSLayoutConstraint constraintsWithVisualFormat:options:metrics:views:]
Fairly easy to answer I think: What to pass if I don't want to use the options paramater of [NSLayoutConstraint constraintsWithVisualFormat:options:metrics:views:]
Passing nil
does work but compiler complains about the obvious wrong type ( void*
instead of NSLayoutFormatOptions
which is a NSUInteger
typedef). 答案很简单,我认为:如果我不想使用
[NSLayoutConstraint constraintsWithVisualFormat:options:metrics:views:]
的选项参数,该怎么办?传递nil
确实有效,但是编译器会抱怨明显的错误类型( void*
而不是void*
NSLayoutFormatOptions
,它是NSUInteger
typedef)。 Is it safe to pass 0 when I don't know about the value of the enums used in the framework? 当我不知道框架中使用的枚举的值时,传递0是否安全?
Regards! 问候!
Use 0. 使用0。
Here is a sample from Working with Auto Layout Programmatically : 这是“以编程方式使用自动布局”的示例:
NSArray *constraints =
[NSLayoutConstraint constraintsWithVisualFormat:@"[button1]-[button2]"
options:0 metrics:nil views:viewsDictionary];
From Apple's documentation you can see that passing 0 is actually the same as NSLayoutFormatDirectionLeadingToTrailing
: 从Apple的文档中,您可以看到传递0实际上与
NSLayoutFormatDirectionLeadingToTrailing
相同:
enum { /* choose only one of these */ NSLayoutFormatAlignAllLeft = NSLayoutAttributeLeft,
枚举{/ *仅选择以下一项* / NSLayoutFormatAlignAllLeft = NSLayoutAttributeLeft,
NSLayoutFormatAlignAllRight = NSLayoutAttributeRight,NSLayoutFormatAlignAllRight = NSLayoutAttributeRight,
NSLayoutFormatAlignAllTop = NSLayoutAttributeTop,NSLayoutFormatAlignAllTop = NSLayoutAttributeTop,
NSLayoutFormatAlignAllBottom = NSLayoutAttributeBottom,NSLayoutFormatAlignAllBottom = NSLayoutAttributeBottom,
NSLayoutFormatAlignAllLeading = NSLayoutAttributeLeading,NSLayoutFormatAlignAllLeading = NSLayoutAttributeLeading,
NSLayoutFormatAlignAllTrailing = NSLayoutAttributeTrailing,NSLayoutFormatAlignAllTrailing = NSLayoutAttributeTrailing,
NSLayoutFormatAlignAllCenterX = NSLayoutAttributeCenterX,NSLayoutFormatAlignAllCenterX = NSLayoutAttributeCenterX,
NSLayoutFormatAlignAllCenterY = NSLayoutAttributeCenterY,NSLayoutFormatAlignAllCenterY = NSLayoutAttributeCenterY,
NSLayoutFormatAlignAllBaseline = NSLayoutAttributeBaseline,NSLayoutFormatAlignAllBaseline = NSLayoutAttributeBaseline,
NSLayoutFormatAlignmentMask = 0xFF, /* choose only one of these three */
NSLayoutFormatAlignmentMask = 0xFF,/ *仅选择这三个中的一个* /
NSLayoutFormatDirectionLeadingToTrailing = 0 << 8, // defaultNSLayoutFormatDirectionLeadingToTrailing = 0 << 8,//默认
NSLayoutFormatDirectionLeftToRight = 1 << 8,NSLayoutFormatDirectionLeftToRight = 1 << 8,
NSLayoutFormatDirectionRightToLeft = 2 << 8,NSLayoutFormatDirectionRightToLeft = 2 << 8,
NSLayoutFormatDirectionMask = 0x3 << 8,NSLayoutFormatDirectionMask = 0x3 << 8,
};};
typedef NSUInteger NSLayoutFormatOptions;
typedef NSUInteger NSLayoutFormatOptions;
Which is considered the default state, so passing 0 is safe. 这是默认状态,因此传递0是安全的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.