【发布时间】:2015-09-18 10:31:03
【问题描述】:
总结(想要tl;dr版本的可以跳到下面的问题):
我刚刚解决了这个问题:Comparing UIDeviceOrienation and UIInterfaceOrientation。在那之后,我看了一下按位是如何工作的(因为我有时见过它们,但并不真正了解它们是如何工作的。)
所以,我研究了What's bitwise operator、How enum in objective-c work with bit、How to use enum that's in bit。
(TL;DR)现在,这是我的问题:
假设我想检查我的 UIInterfaceOrientation = Landscape (Left | Right) 是否应该像这样使用它:
[UIApplication sharedApplication].statusBarOrientation ==
(UIInterfaceOrientationLandscapeLeft |
UIInterfaceOrientationLandscapeRight)
或
[UIApplication sharedApplication].statusBarOrientation &
(UIInterfaceOrientationLandscapeLeft |
UIInterfaceOrientationLandscapeRight)
他们应该给出相同的结果吗?还是不一样?哪个更合适?
(在我的简单想法中,如果没有错,那么第二个更合适)。
额外问题
除了枚举,还有什么地方可以有效地使用按位移位运算符吗?
【问题讨论】:
标签: objective-c enums comparison bitwise-operators