iPhone: Some Views Landscape others Portrait
I've got a tabbar setup with a few tabs. The first tabitem is viewcontroller that programmatically loads a xib that is laid out in portrait. When the user ro开发者_开发技巧tates the phone, it automatically presents a modal view that is laid out in landscape. This mechanism works fine.
When the device is rotated to portrait mode, it dismisses the modal view and a tabbar is visible at the bottom. I would like for some of my other tabbar items such as a scrollview and an webview to autorotate to landscape when the device is rotated.
I've implemented a class called RotateTabBarViewController which contains the shouldAutorotateToInterfaceOrientation method and checks the value of the same method on the selectedViewController. So if I have the shouldAutorotateToInterfaceOrientation method in my webview returning true then the view will rotate as expected.
Here's the problem. While the rotated view is in landscape mode, the tabbar is still visible meaning a user can click the icon for the first item. When the first item is clicked it knows it's in landscape mode and automatically loads the modal view again. The only problem is the view is offset on the screen.
I'm looking for a solution that will realign the modal view to where it's supposed to be. I'm not sure if it's the main view that needs to be realigned or just the modal view.
The following link contains a demo of the concept.
http://www.veryniceindustries.com/rotation_demo.zip
- Rotate the device to portrait
- Select Item Two
- Rotate the device to landscape (need some help realigning this view)
- Select Item One (modal appears for landscape, but is offset)
Any help would be greatly appreciated.
Best, Howie
Have you considered implementing the viewWillAppear method on viewController #1, and correcting the frame of the view?
Alternatively handling it in the itemOneViewController on in the orientationChanged or updateItemOneView methods?
PS: thanks for suppling the source code, as a young Obj-C programmer is always nice to see how someone else approaches a problem.
精彩评论