she swears <i>geek</i> is a term of endearment

iPhone Rotation Woes and a Simple Solution

Short and to the point. Either start your application by carefully designing for rotation, or don’t rotate. If you use a UITabBarController, each UIViewController that is associated with a tab will be asked shouldAutorotateToInterfaceOrientation. If any of them return “NO”, then its no. Furthermore, it is next to impossible (as of this writing) to force orientation on a View when navigating from a different View that supports an alternate orientation. For example, if your list navigates to a detail page that supports landscape and then the user navigates up to your list that does not - too bad. To avoid hours and hours of pain and anguish trying to correct for rotation and resizing issues, I have two suggestions: 1) design and test constantly from the very beginning OR 2) Don’t rotate.

In My app, I wanted to show a different view entirely, from my detail view, when the phone was turned to landscape. That should have been really easy, or so I thought. My other Views were not auto-resizing according to the documentation, and no code I could come up with would cause layout to display correctly in all cases, so I was eventually forced to suppress navigation when the landscape view was shown. That should have been really easy, or so I thought. When I rotated with the navigation and tool bar present, everything was displaying perfectly. Unfortunately, navigating to another view resulted in failure to resize and reformat. If I hid the tab bar using hidesBottomBarWhenPushed, returning to portrait caused the view to just vanish. I easily wasted 40 hours on the whole of this problem.

My solution, in the end, was to use a modal view by calling [self presentModalViewController:myViewController animated:YES];. This way, the modal view is shown on top of navigation. I can dismiss this view and everything remains where it should be (actually, it rotates back, but correctly). Now I can display a landscape view without exposing other views to this orientation. Keep in mind that any view associated with a tab on the tab bar can cancel rotation. Therefore, I set a bool to indicate whether the view has focus in viewDidAppear and viewDidDisappear, respectively. Using this bool, I can return YES when not focused assuming the other views prevent navigation back to the view that doesn’t play ball in that aspect.

I am pleased to announce that my app is finally ready for submission and I think its useful and of very high quality. I am not, however, even remotely excited to build another. I am actually looking forward to taking a break from the iPhone platform. I’ll be grateful when Apple brings the sdk up a notch in its quality, consistency and usefulness. The device is completely ground-breaking and a marvel of engineering. The development platform is not

Leave a Reply