gpt4 book ai didi

ios - [NSLayoutConstraint constraintsWithVisualFormat :options:metrics:views:] 的选项参数作为 NULL 值传递的内容

转载 作者:行者123 更新时间:2023-11-28 21:47:16 24 4
gpt4 key购买 nike

我认为很容易回答:如果我不想使用 [NSLayoutConstraint constraintsWithVisualFormat:options:metrics:views:] 的选项参数,应该传递什么 传递 nil 确实有效,但编译器提示明显的错误类型(void* 而不是 NSLayoutFormatOptions,它是 NSUInteger typedef)。当我不知道框架中使用的枚举的值时传递 0 是否安全?

问候!

最佳答案

来自 Apple's documentation可以看到传0其实和NSLayoutFormatDirectionLeadingToTrailing是一样的:

enum { /* choose only one of these */ NSLayoutFormatAlignAllLeft = NSLayoutAttributeLeft,
NSLayoutFormatAlignAllRight = NSLayoutAttributeRight,
NSLayoutFormatAlignAllTop = NSLayoutAttributeTop,
NSLayoutFormatAlignAllBottom = NSLayoutAttributeBottom,
NSLayoutFormatAlignAllLeading = NSLayoutAttributeLeading,
NSLayoutFormatAlignAllTrailing = NSLayoutAttributeTrailing,
NSLayoutFormatAlignAllCenterX = NSLayoutAttributeCenterX,
NSLayoutFormatAlignAllCenterY = NSLayoutAttributeCenterY,
NSLayoutFormatAlignAllBaseline = NSLayoutAttributeBaseline,

NSLayoutFormatAlignmentMask = 0xFF, /* choose only one of these three */
NSLayoutFormatDirectionLeadingToTrailing = 0 << 8, // default
NSLayoutFormatDirectionLeftToRight = 1 << 8,
NSLayoutFormatDirectionRightToLeft = 2 << 8,
NSLayoutFormatDirectionMask = 0x3 << 8,
};

typedef NSUInteger NSLayoutFormatOptions;

这被认为是默认状态,因此传递 0 是安全的。

关于ios - [NSLayoutConstraint constraintsWithVisualFormat :options:metrics:views:] 的选项参数作为 NULL 值传递的内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29629702/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com