I just tried adding some print statements to my shouldautorotate method and noticed that it checks it 4 times which does make sense but even though I am not switching mode from portrait to landscape,
it returns portrait 3 times and on the fourth time, it returns landscape even though my simulator is not in landscape.
if(interfaceOrientation == UIInterfaceOrientationLandscapeLeft){
NSLog(@"landscape left");
}else if (interfaceOrientation == UIInterfaceOrientationLandscapeRight) {
NSLog(@"landscape right");
}else if(interfaceOrientation == UIInterfaceOrientationPortrait){
NSLog(@" portrait");
}else if(interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown){
NSLog(@"portrait upsidedown");
}
Any one knows why?
Try putting that code into the
didAutorotateor thewillAutorotatemethod.shouldAutorotateis only supposed to return YES or NO.I’m theorising that
shouldAutorotateis checked regularly, whereasdidAutorotateis only fired of when it detects an orientation shift.This is the code I use to check:
That is in a method I created called
reOrientwhich is called from mydidAutorotateJust make sure when you create a new method like reOrient that you declare it in the header as well (I kept forgetting when I was starting out) as below: