UIViewController didRotateFromInterfaceOrientation参数fromInterfaceOrientation返回垃圾值

时间:2011-07-13 09:12:14

标签: ios uiview rotation

在测试过程中将iPhone颠倒过来时,我发现了

- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation

被调用,作为参数传入的UIInterfaceOrientation参数是垃圾值(即Apple文档中定义的一些随机整数,而不是UIInterfaceOrientation常量)。如何让它返回有效值?

1 个答案:

答案 0 :(得分:3)

它没有返回垃圾值。

将值与以下常量进行比较:

UIInterfaceOrientationLandscapeLeft;
UIInterfaceOrientationLandscapeRight;
UIInterfaceOrientationPortrait;
UIInterfaceOrientationPortraitUpsideDown;

if (fromInterfaceOrientation == UIInterfaceOrientationPortrait) {
     NSLog(@"PORTRAIT");
}

或使用以下BOOL宏:

UIInterfaceOrientationIsLandscape(fromInterfaceOrientation);
UIInterfaceOrientationIsPortrait(fromInterfaceOrientation);

if (UIInterfaceOrientationIsPortrait(fromInterfaceOrientation)) {
    NSLog(@"PORTRAIT");
}