0

I have a view in my app that has three segmentedButtonControllers and I designed it with portrait mode. When I rotate the screen the whole UI is...just not right.

enter image description here enter image description here

My question is, should I design for both portrait and landscape mode separately? If so how I do that?

ps. Actually I don't need rotation support for iPhone's app but I'm planning to make same app for iPad where every view has to be rotatable.thanks.


Edit: just found good example Easiest way to support multiple orientations? How do I load a custom NIB when the application is in Landscape?

Community
  • 1
  • 1
bicbac
  • 435
  • 1
  • 9
  • 20

4 Answers4

3

I'd say it depends on the content. Sometimes it's enough to set the autoresizing of the UI elements in the Inspector of the Interface Builder properly and you get a satisfying effect, but there are cases where just resizing the view doesn't make the best use of the screen real estate. In your case for example just extending the segmented controls to the full width is probably not going to be as nice as arranging them next to each other to make the place for the text at the bottom.

If you are going to design for both modes separately, you can have them as different views and switch between the accordingly. Good example can be found in the 4th chapter of iPhone Cookbook. What the author does there is to switch the view when the orientation changes as follows :

- (BOOL)shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation) interfaceOrientation
 { 
     if ((interfaceOrientation == UIInterfaceOrientationLandscapeLeft)
        || (interfaceOrientation == UIInterfaceOrientationLandscapeRight))
       self.view = landscapeView;
    else if ((interfaceOrientation == UIInterfaceOrientationPortrait)
        || (interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown))
       self.view = portraitView;
    return YES;
 }
Tomas Vana
  • 18,317
  • 9
  • 53
  • 64
1

I strongly recommend you look up the UIViewController class in docs and read it all (assuming you haven't already). The key methods you need include willRotateToInterfaceOrientation:duration:, described as follows:

willRotateToInterfaceOrientation:duration: Sent to the view controller just before the user interface begins rotating.

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration

Parameters toInterfaceOrientation The new orientation for the user interface. The possible values are described in UIInterfaceOrientation. duration The duration of the pending rotation, measured in seconds. Discussion Subclasses may override this method to perform additional actions immediately prior to the rotation. For example, you might use this method to disable view interactions, stop media playback, or temporarily turn off expensive drawing or live updates. You might also use it to swap the current view for one that reflects the new interface orientation. When this method is called, the interfaceOrientation property still contains the view’s original orientation.

This method is called regardless of whether your code performs one-step or two-step rotations.

Availability Available in iOS 2.0 and later.

It sounds like you should also include:

 - (BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return NO;
}
Ken
  • 30,811
  • 34
  • 116
  • 155
0

I was looking for a solution and finally have chosen to set the layout elements programatically, as described in this article.

The iOSDev
  • 5,237
  • 7
  • 41
  • 78
Ole
  • 1
0

Just set the autoresizingMask property of your control to

UIViewAutoresizingFlexibleWidth
Mihir Mehta
  • 13,743
  • 3
  • 64
  • 88