我按比特有点失落;)如何使UIInterfaceOrientation枚举测试值
我的目标是要获取一整套通过应用支撑取向和测试每个结果值更新自定义变量。 我的问题是,我不知道怎么做的比较(我有一个转换/测试问题...)
首先,我读这篇文章:Testing for bitwise Enum values 但是它不带我光.. 。
让说我有以下的方向申报我的应用程序(以下是我的变量supportedOrientations日志输出): 支撑取向=( UIInterfaceOrientationPortrait )
所以我的第一次尝试是尝试整数值一些测试,但它不工作(即使应用程序被宣布为在纵向模式下测试返回“假”):
NSArray *supportedOrientations = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"UISupportedInterfaceOrientations"];
NSLog(@"[supported orientations = %@", supportedOrientations);
// for clarity just make a test on the first orientation we found
if ((NSInteger)supportedOrientations[0] == UIInterfaceOrientationPortrait) {
NSLog(@"We detect Portrait mode!");
}
我的第二次尝试尝试按位的事情但这次它总是返回'真'(即使支持的方向不是UIInterfaceOrientationPortrait)。 :
NSArray *supportedOrientations = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"UISupportedInterfaceOrientations"];
NSLog(@"[supported orientations = %@", supportedOrientations);
// for clarity just make a test on the first orientation we found
if ((NSInteger)supportedOrientations[0] | UIInterfaceOrientationPortrait) { // <-- I also test with UIInterfaceOrientationMaskPortrait but no more success
NSLog(@"We detect Portrait mode!");
}
所以我的问题是:
如何测试方向在我的情况?
这是一种通过使用按位事件(使用|操作数)来使用测试的方法吗?