views:

2744

answers:

2

Hi Guys,

I have one view controller set with one graph view and segmented control inside it. How to make the view rotate to horizontal? Also, is it possible to load another view for horizontal orientation?

Thx in advance, Mladen

+2  A: 

You implement orientation support through:

- (BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
{
// Just delete the lines for the orientations you don't want to support
  if((toInterfaceOrientation == UIInterfaceOrientationPortrait) ||
     (toInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown)) ||
     (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft)) ||
     (toInterfaceOrientation == UIInterfaceOrientationLandscapeRight))  {   
   return YES; 
   }
return NO;
}

Then to load a new ViewController when rotating:

- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
{
  if((fromInterfaceOrientation == UIInterfaceOrientationLandscapeLeft) ||
     (fromInterfaceOrientation == UIInterfaceOrientationLandscapeRight))
  {    
    // Load the view controller you want to display in portrait mode...
  }
}

You could even set up an animation to manipulate the alpha property of the new view, if you wanted to do a smooth transition, like you see in the iPod app when it transitions to CoverFlow mode.

DISCLAIMER The preferred method of supporting interface rotation changes in 3.0. The above method will still work, but there is a way to get smoother animation. But we're not supposed to talk about that here for one. more. week.

mmc
A: 

For device rotation you should implement this method in your viewController:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation

Chilloutman