I need to know when orientation switch from portrait to landscape and vise versa.
If I choose to listen to UIDeviceOrientationDidChangeNotification I get face up, face down etc, but I need to run code only when there is a interface rotation.
I could do as http://the.ichibod.com/kiji/how-to-handle-device-rotation-for-uiviews-in-ios/
- (void)deviceOrientationDidChange:(NSNotification *)notification {
//Obtaining the current device orientation
UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];
//Ignoring specific orientations
if (orientation == UIDeviceOrientationFaceUp || orientation == UIDeviceOrientationFaceDown || orientation == UIDeviceOrientationUnknown || currentOrientation == orientation) {
return;
}
[NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(relayoutLayers) object:nil];
//Responding only to changes in landscape or portrait
currentOrientation = orientation;
}
What is the best approach?
I had similar problems orientating my views when using device orientation. It has up, down, left and right but also unknown and another which I yet to figure it out what it means (int 5 on the enum, 0 being Unknown). Anyways, what I ended up resorting to was to detect the status bar orientation. That remains more consistency for what the user is seeing.
Hope this helps.