常用符号"|"表示在Objective-C中 [英] Frequently used symbol "|" in Objective-C

查看:96
本文介绍了常用符号"|"表示在Objective-C中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

self.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleWidth;

上面显示了源代码. 想知道符号"|"是什么代表? 非常感谢您的回答,并感谢您的答复;)

The source code is shown above. Wonder what the symbol "|" stands for? Will really appreciate your answer and thanks for the reply;)

推荐答案

简而言之:这是通常用于生成位掩码.

通过此操作,您可以将标志合并为二进制数.

With this operation you can combine flags into on binary number.

例如:声明:

self.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleWidth;

本质上与以下内容相同:

is esentially the same as:

self.autoresizingMask = UIViewAutoresizingFlexibleWidth;

(因为两个操作数相同).

(since both operands are the same).

如果您要询问:

self.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight;

这会将self.autoresizingMask设置为:

(1<<1)|(1<<4)=(0b 0000 0010)|(0b 0001 0000)=0b 0001 0010 = 9

不要将简单真/假代数.

两者之间存在某种关系(按位或可以理解为逻辑或相同位置上的位之间有关系).

There is some relation between the two (bitwise or can be understood as a logical or between the bits on the same position) but that is about it.

这篇关于常用符号"|"表示在Objective-C中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆