How do you force a view to be in landscape mode? I've tried the following code (which generates a warning), but it isn't working for me (in the view controller):
Use the search function. There's already several topics up here which deal with landscape mode...
i have searched throughout multiple forums and have found lots of information about an entire application in landscape, but almost nothing about just one view displaying in landscape orientation. I have my application displaying in portrait and want one view to display in landscape. Could you please show me where this is discussed?
thanks for the fast response. I appreciate the examples and they are helping me to understand. We were able to start the "Window" and "tableview" in landscape but the NavigationBar is not transforming. Here is a snapshot of our code:
Code:
- (void)loadView {
// create and configure the table view
myTableView = [[UITableView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame] style:UITableViewStylePlain];
myTableView.delegate = self;
myTableView.dataSource = self;
myTableView.autoresizesSubviews = YES;
myTableView.scrollEnabled = YES;
// BWC: allows the TableView to resize in landscape or portrait orientation
myTableView.autoresizingMask = UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth;
// this will transform your coordinates so that you can draw kind of normally
// Set up to rotate 90 degrees (PI/2 radians)
CGAffineTransform rotate = CGAffineTransformMakeRotation(1.57079633);
[myTableView setTransform:rotate];
self.view = myTableView;
}
Please let me know if you think there is something we are not doing correctly. One thing that may be the problem is the fact we are setting up a UIView.
I think you should apply transformation to every UI element that you want to render in landscape...
But I don't quite get it. If you have a navigation bar that means that you have a navigation controller as well? Why don't you use the autorotate functionality that view controllers serve to you? It's much easier and the whole interface is rotatet for you. Just need to return YES shouldRotateToInterfaceOrientation ...
I think you should apply transformation to every UI element that you want to render in landscape...
But I don't quite get it. If you have a navigation bar that means that you have a navigation controller as well? Why don't you use the autorotate functionality that view controllers serve to you? It's much easier and the whole interface is rotatet for you. Just need to return YES shouldRotateToInterfaceOrientation ...
Cheers
That is true. We are using a navigation controller and have tried to use the shouldAutorotateToInterfaceOrientation function. Here is the code we are using for that function.
As far as I understand it, that should allow the phone to autorotate to Landscape Right when rotated on its side. The only problem is that the view first loads in portrait and we want it load and be viewed only in landscape right. We are basically trying to show tableview in landscape mode because the information that will be displayed is easier to read in landscape than in portrait.
Sorry for the confusion but hopefully this will help explain what we are trying to do.
Yeah I understand. I have simmilar situation in my app. Then the only way to go is to apply rotation transformation manually to all the views. I'm doing it so. I haven't seen other methods for doing that.
Maybe there is one thing you could try. It might work:
- create a single UIView that will be uses as a wrapper for your UINavigationController (and it's subviews)
- add this UINavigationController as a subview to that view
- apply rotation transformation on that wrapper view. that should apply the rotation to all it's subviews. At list I think it should.
Yeah I understand. I have simmilar situation in my app. Then the only way to go is to apply rotation transformation manually to all the views. I'm doing it so. I haven't seen other methods for doing that.
Maybe there is one thing you could try. It might work:
- create a single UIView that will be uses as a wrapper for your UINavigationController (and it's subviews)
- add this UINavigationController as a subview to that view
- apply rotation transformation on that wrapper view. that should apply the rotation to all it's subviews. At list I think it should.
and ofcourse report back if it's working
I tried that and it was unsuccessful. I will figure it out. Thanks again for the help and advice.
As you can see we are manually transforming the views and restoring the correct views. There is one problem interface bug when you leave this view, but nothing major.
So I'm having a strange problem. I'm doing something similar to what you're doing, but I hide the UINavigationBar after a delay. However, when the user brings it back (via a click), it comes back sized for portrait mode. Any thoughts as to how to force the UINavigationController to redraw the bar correctly (note that the first time it draws after the transformation, it draws correctly).
I found A solution. It might not be THE solution, but at least it works. I messed around with the code above but could never get rid of the white bar on the left where the status bar was. This solution takes care of that by creating a whole new window.
I found A solution. It might not be THE solution, but at least it works. I messed around with the code above but could never get rid of the white bar on the left where the status bar was. This solution takes care of that by creating a whole new window.
I tried this approach (second window) and it worked fine. The previous one, based on transformation only, did not work for me (the transition was not so smooth and there was a blank space in the left side - the size of the status bar).
However, after releasing the second window, I need to update the screen I was in (a table view controller). I need this in order to update the text in the cell that triggered the call to the landscape window. I have implemented the viewWillAppear, and called a reload table in there. This works fine in regular navigation use, but in this case, the viewWillAppear method is not called in the first window when the second one disappears.
However, after releasing the second window, I need to update the screen I was in (a table view controller). I need this in order to update the text in the cell that triggered the call to the landscape window. I have implemented the viewWillAppear, and called a reload table in there. This works fine in regular navigation use, but in this case, the viewWillAppear method is not called in the first window when the second one disappears.