I have created a binary clock and am using the
willAnimateToInterfaceOrientation: duration:
method to place the on/off buttons for either the portrait or landscape orientation. I have two tabs, the first of which is the binary clock itself, and the second of which are instructions for how to read the clock.
Here's the issue. The iPad's main screen automatically switched from portrait to landscape, so I can start my app in either orientation. The iPhone, on the other hand, only displays its main screen in portrait orientation. This is fine, but when I fire up my app, push either tab button, then change the orientation, while the screen (clock or instructions) changes orientation, selecting the other tab button displays that content in the previous orientation. Within the same view (clock or instructions), orientation changes perform perfectly, but when switching from one view to the other, after having changed the orientation, the content is not displayed correctly.
In other words, say I fire up my app on the iPad in landscape orientation. By default, the binary clock view appears. Were I to change to portrait orientation, the clock changes as expected. Were I then, keeping my iPad oriented in portrait mode, to press the instructions tab button, either the content and the iAd banner (or sometimes just the iAd banner) is displayed in landscape orientation. The only solution, thus far, is to change the orientation from the current setting to the other, then back again, but that is hardly acceptable.
Is there a different method I can use to check the orientation when the view is called and display the content correctly? Obviously what I have is not working correctly.
If you move things dinamically on the view basing on the orientation, you have to check the current orientation in two places:
in the willAnimate
... Method, and this is ok. This method is called when a rotation occurs AND the main VC view is visible.
in the viewWillAppear
method!
If the orientation is changed when a VC is not visible, the willAnimate
... Method is not called. So, before displaying the view, you should check the device orientation and setup your view/sub views correctly.
Simply use [[UIDevice currentDevice] orientation];
method in viewWillAppear
to check what is the current orientation and setup your view correctly