I'm trying to detect any device orientation change so that I can update the views.
I want to update the views whether the orientation is portrait or landscape, so I implemented this method:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations.
return (interfaceOrientation == UIInterfaceOrientationPortrait || interfaceOrientation == UIInterfaceOrientationLandscapeRight || interfaceOrientation == UIInterfaceOrientationLandscapeLeft);
}
I know that if I want to update the views to show properly for the current orientation, I will need to implement some of the following methods:
– willRotateToInterfaceOrientation:duration:
– willAnimateRotationToInterfaceOrientation:duration:
– didRotateFromInterfaceOrientation:
– willAnimateFirstHalfOfRotationToInterfaceOrientation:duration:
– didAnimateFirstHalfOfRotationToInterfaceOrientation:
– willAnimateSecondHalfOfRotationFromInterfaceOrientation:duration:
Now, the problem is that I don't understand why none of these methods get fired when I rotate the simulator.
I tried as well this piece of code:
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
But still nothing. So I'm wondering, does the simulator fire rotation notifications? If yes, what am I doing wrong?
Quick summary, change this:
to this:
I'm sorry if I took somebody's time for a silly mistake of mine. I found out why the method
– willRotateToInterfaceOrientation:duration:
would never get called. Something brought my attention to the navigation controller:I found these post in another forum and I had a look at the app delegate. My code was as follows:
The problem was that I was not setting any view controller for the window, but I was just adding a view. It was a mistake I did due to the hurry to test something. I had to fix the code like this:
You need to add notification observer something like
and add the method