How to determine the rotation on the iPhone without autorotizing the device?

Does anyone know how to do this?

I thought:

-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { return YES; } - (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration { } - (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation duration:(NSTimeInterval)duration { } - (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation { } - (void)willAnimateFirstHalfOfRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration { } - (void)didAnimateFirstHalfOfRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation { } - (void)willAnimateSecondHalfOfRotationFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation duration:(NSTimeInterval)duration { } 

may interfere with device rotation (overriding all rotation methods of my UIViewController and not calling a superclass), but I'm afraid that it is not a UIViewController that actually performs the rotation.

My UIViewController is in the UINavigationController.

Does anyone have any idea?

Cheers, Nick.

+2
iphone cocoa-touch rotation
Jun 15 '09 at 11:58
source share
3 answers

You can register to notify UIDeviceOrientationDidChangeNotification (from UIDevice.h ), and then when you care about orientation changes, call this method:

 [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications]; 

When you no longer care about orientation changes, call this method:

 [[UIDevice currentDevice] endGeneratingDeviceOrientationNotifications]; 

A notification will be sent when applicable, and you can check the [UIDevice currentDevice].orientation to find out what the current orientation is.

+20
Jun 15 '09 at 16:29
source share

On the side of the note, shouldAutoRotateToInterfaceOrientation is used to call during rotation in 2.x, but in 3.0 it is much less consistent. The notification mentioned in another post is the way to reliably indicate a turn.

+4
Jun 15 '09 at 20:26
source share

You are returning YES from shouldAutorotateToInterfaceOrientation: which I suspect you did not want to do. This is the only method that needs to be implemented to prevent the device from rotating.

As for getting the current device orientation, you can use [[UIDevice currentDevice] orientation] .

+1
Jun 15 '09 at 12:36
source share



All Articles