views:

334

answers:

1

Hey there,

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 rotates 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%5Fdemo.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

A: 

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.

Jonathan
Thanks for the response - but I'm such a noob I'm don't know how to change the frame. Is it a matter of just passing a new frame to "self" in the viewWillAppear method or is it something more involved? Happen to have a snippet I can check out?Thanks,Howie
Ward
Well UIViewController is isn't a UIView, so you actually want something like [self.view setFrame:UITabBarController.view.frame].UITabBarController should be the instance of UITabBarController you are using. You can make a reference in IB and assign it to ivar so you can reference it easily.frames are C structs called CGRect, you can make them with CGRectMake()
Jonathan
looks like the origin of both the itemOneViewController view and the itemOneLandscapeViewController view are both 0,0. Is it possible something else is moving when I go from one tabbar item to another?
Ward
The origin is the position from the top left hand corner of screen. If you notice the view sticks in this area. You want to look at the bounds on the parent view.[UIView superview]. The bounds.size.width of this should indicate the new width.
Jonathan