在测试过程中将iPhone颠倒过来时,我发现了
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
被调用,作为参数传入的UIInterfaceOrientation参数是垃圾值(即Apple文档中定义的一些随机整数,而不是UIInterfaceOrientation常量)。如何让它返回有效值?
答案 0 :(得分:3)
它没有返回垃圾值。
将值与以下常量进行比较:
UIInterfaceOrientationLandscapeLeft;
UIInterfaceOrientationLandscapeRight;
UIInterfaceOrientationPortrait;
UIInterfaceOrientationPortraitUpsideDown;
即
if (fromInterfaceOrientation == UIInterfaceOrientationPortrait) {
NSLog(@"PORTRAIT");
}
或使用以下BOOL宏:
UIInterfaceOrientationIsLandscape(fromInterfaceOrientation);
UIInterfaceOrientationIsPortrait(fromInterfaceOrientation);
即
if (UIInterfaceOrientationIsPortrait(fromInterfaceOrientation)) {
NSLog(@"PORTRAIT");
}