简体   繁体   English

[NSLayoutConstraint ConstraintsWithVisualFormat:options:metrics:views:]的options参数作为NULL值传递的内容

[英]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, // default NSLayoutFormatDirectionLeadingToTrailing = 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.

相关问题 NSLayoutConstraint.constraintsWithVisualFormat在Swift 2.0中的options参数中传递nil - NSLayoutConstraint.constraintsWithVisualFormat pass nil in options parameter in Swift 2.0 无法使用类型&#39;的参数列表调用&#39;constraintsWithVisualFormat&#39;(字符串,选项:nil,metrics:nil,views:Dictionary <String, UIView!> )” - Cannot invoke 'constraintsWithVisualFormat' with an argument list of type '(String, options: nil, metrics: nil, views: Dictionary<String, UIView!>)' 可以将constraintsWithVisualFormat与未知数量的视图一起使用吗? - Can constraintsWithVisualFormat be used with an unknown number of views? ConstraintsWithVisualFormat为所有视图设置相同的Y位置 - constraintsWithVisualFormat set same Y position for all the views 可以将constraintsWithVisualFormat与动态生成的视图一起使用吗? - Can constraintsWithVisualFormat be used with dynamically generated views? 无法将类型为“NSLayoutConstraint”的不可变值作为inout参数传递 - Cannot pass immutable value of type 'NSLayoutConstraint' as inout argument 添加NSLayoutConstraint使视图消失 - adding NSLayoutConstraint makes views disappear UITableView中的heightForRowAtIndexPath有哪些替换选项? - What replacement options are there for heightForRowAtIndexPath in a UITableView? Xcode 中的库链接选项是什么? - What are the libraries linking options in Xcode? 智能手机与智能手机通信 - 有哪些选择? - Smartphone to smartphone communication - what are the options?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM