-2

Possible Duplicate:
iOS 6 shouldAutorotate: is NOT being called

I need an method to knows when user change the orientation...

I have tried

-(BOOL) shouldAutorotate { //never called

UIInterfaceOrientation toInterfaceOrientation = [[UIDevice currentDevice] orientation];
if(toInterfaceOrientation == UIInterfaceOrientationPortrait)
    //a code here

return YES;
}

How can I know when the user change the orientation of iPad?

Community
  • 1
  • 1
Ladessa
  • 985
  • 4
  • 24
  • 50

2 Answers2

2

Remember to set the supported orientations in the info.plist.

Try using

  - (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration;
  - (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation;

(Deprecated in iOS 6.0)

  - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation;
Popeye
  • 11,839
  • 9
  • 58
  • 91
0

Make sure you call this first:

[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];

Then track orientation change here:

-(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
    //your code here 
}

The duration here is important, as that's the amount of time it will take for the orientation change to be complete. It is only at this point that the new orientation will be completely set

ozarius
  • 134
  • 1
  • 3
  • willRotateToInterfaceOrientation never called – Ladessa Dec 03 '12 at 15:52
  • I have this running on my production code, and just to humor myself, i went back and debugged that code in iOS6/iPad2, and i can assure you, this is certainly called when the orientation is going to change. – ozarius Dec 03 '12 at 16:01