tags:

views:

1007

answers:

2

I understand you can specify a landscape , for the entire application but what if its partially in landscape and partially in portrait.

Currently I have some views that are basically Images. These images have been rotated so that the user knows certain sections of the application are going to be in Landscape mode. All my UILabels are also rotated to give this effect as well.

My question is, is there a better way to handle this. Is there a way to set the orientation programatically at run time? In which case I would no longer need to rotate my images/uilabels.

Just to clarify, I do not need auto rotation functionality, the way that it is being implemented now is captures all the functionality i want to include in the app but I just wanted to know if there is a less cumbersome way of handling landscape/portrait views within the same application.

A: 

Currently I do not know of any way to control orientation programatically. Meaning there is no way to tell the device "rotate to landscape now". You can only specify things like:

(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation

You can specify what view controllers support what orientations, and react to the orientation changes by overriding functions, however when and how those functions are called is determined by the system. You can get more detailed messages from the UIDevice class too.

If I understand correctly what you are saying, your app is essentially always in one single orientation, however you are just drawing your various views differently to make it seem like certain parts of the app are in portrait/landscape mode? It sounds like you are trying to fit a square in a round hole, the iPhone's orientation API's weren't designed for that kind of behavior, and you are better off working with the API's than against them.

+3  A: 

You can force rotation at any time by calling;

UIApplication *application = [UIApplication sharedApplication];    
[application setStatusBarOrientation: UIInterfaceOrientationWHATEVER animated:NO];

My current application is primarily landscape, but has a few portrait views. In the view controllers corresponding to views the user should be able to rotate, I am allowing the rotation but preventing animation. This gives you a switch to another view in your NIB, without any weird slide-off-the-screen screwyness that normally happens is you pile on a view during the animation.

Hopefully you find this helpful!

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
if (interfaceOrientation == UIInterfaceOrientationPortrait) {
 rotatingToPortrait = YES;
 [UIView setAnimationsEnabled:NO];
 return YES;
} else if (interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight) {
 rotatingToPortrait = NO;
 [UIView setAnimationsEnabled:NO];
 return YES;
}
// Catch upside-down
return NO; }

- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation {
[UIView setAnimationsEnabled:YES];
if (rotatingToPortrait) {
 // Swap in portrait view here
} else {
 // Swap it out here
} }
Carson C.