我只是在查看 UIKit 中的 NSText.h,下面这段代码引起了我的注意
/* Values for NSTextAlignment */
typedef NS_ENUM(NSInteger, NSTextAlignment) {
NSTextAlignmentLeft = 0, // Visually left aligned
#if TARGET_OS_IPHONE
NSTextAlignmentCenter = 1, // Visually centered
NSTextAlignmentRight = 2, // Visually right aligned
#else /* !TARGET_OS_IPHONE */
NSTextAlignmentRight = 1, // Visually right aligned
NSTextAlignmentCenter = 2, // Visually centered
#endif
NSTextAlignmentJustified = 3, // Fully-justified. The last line in a paragraph is natural-aligned.
NSTextAlignmentNatural = 4, // Indicates the default alignment for script
} NS_ENUM_AVAILABLE_IOS(6_0);
为什么 NSTextAlignmentRight 和 NSTextAlignmentCenter 的值被翻转为 TARGET_OS_IPHONE 而不是?
在 iOS 6 之前,iOS 没有 NSTextAlignment
。 iOS 使用 UITextAlignment
。 Center
值为 1
,Right
值为 2
。
然后在 iOS 6 中,添加了 NSTextAlignment
。为了保持向后兼容性,NSTextAlignmentCenter
被赋予与 UITextAlignmentCenter
相同的值。 Right
也一样。
iOS 上的 NSTextAlignment
枚举与已弃用的 UITextAlignment
匹配比与 OS X 中的值相同更为重要。
iOS 上的 UITextAlignment
和 OS X 上的 NSTextAlignment
之间最初的区别可能是一个简单的疏忽。但这是一个简单的猜测。
关于ios - 为什么为 TARGET_OS_IPHONE 定义不同的 NSTextAlignment 枚举?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28175864/
欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) | Powered by Discuz! X3.4 |