Question

I have a UIScrollView with sub-views whose frames I have to update on orientation change. I have been running the program on an iPhone simulator but it looks like the UIDeviceOrientationDidChangeNotification does not return the correct orientation of the device. It returns UIInterfaceOrientationPortrait when I rotate to UIInterfaceOrientationLandscapeLeft/Right and vice versa. Am I not using it right or do I have to use some other method of handling orientation change?

Was it helpful?

Solution

UIInterfaceOrientation != UIDeviceOrientation. UIInterfaceOrientation is declared as ...

typedef enum : NSInteger {
   UIInterfaceOrientationPortrait           = UIDeviceOrientationPortrait,
   UIInterfaceOrientationPortraitUpsideDown = UIDeviceOrientationPortraitUpsideDown,
   UIInterfaceOrientationLandscapeLeft      = UIDeviceOrientationLandscapeRight,
   UIInterfaceOrientationLandscapeRight     = UIDeviceOrientationLandscapeLeft
} UIInterfaceOrientation;

... portrait contains same values / numbers, but landscape variants are swapped, etc. You didn't show your code, so, I can just assume, that you're mixing these two things together.

Is there any reason why you're not using willRotateTo..., willAnimateRotation..., didRotateFrom... methods of UIViewController?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top