Iphone + main Window + orientation problem - iphone

I have MainWindow.xib in the application.
In the Interface Builder, I rotate the main window from portrait to landscape and than put few UIControls on it.
Than I save it.
After that when I run the application although during design time I made everything in landscape mode, it always displays things in portrait mode.
Please help me

In addition to overriding shouldAutorotate to say what orientations you support, you should also set the "initial interface orientation" key in your info.plist file to set your preferred initial orientation.
For more information, search for "Launching in Landscape Mode" in the iPhone Application Programming Guide.

IB just sets up your XIB files. It's your view controller that manages the orientation.
The default UIViewController or UINavigation controller has details on this.
Specifically, you need to overload
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown ? NO : YES);
}
Have a look at the documentation for UIViewController for more info.

Related

Rotate only one view controller in a tabbed application

I've read to many posts but I can't find a solution.
I've a tabbed application using storyboard. All the View Controllers of that Tabbed Application must show the content in portrait orientation, but there's only one viewcontroller (which is showing a video) that I want to be in landscape mode.
EXPLANATION OF THE STORYBOARD: TabBarController -> 4x Navigation controllers -> each navigation controller points to his ViewController -> one of these view controllers have an image, when I press that image, i've done a push to another view, the view that I want to have in landscape mode because I have there a UIWebView to show a video.
I'm unable to have all the app only in portrait orientation and the viewcontroller mentioned capable to rotate in landscape mode.
My app is also supporting iOS 5, so I know there are methods deprecated and I'm getting crazy.
I believe that in Summary > iPhone / iPod Deployment info > Supported Interface Orientations > there I've to check Portrait, Landscape left and right, and then via methods, enable or disable the rotations. I'm lost.
Can you help me?
I think you should be able to do this if you push to the view as a modal. Make sure your application's PList file (under Supporting Files folder) is set to support all orientations and then simply add the code to the modal view controller to display landscape with something like this.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOr‌​ientation
{
return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft);
}
Let me know if you have any luck.
As i worked out for my App i advise you to use this solution.By using some conditions in the shouldAutorotateToInterfaceOrientation method orientation type we can solve this.Just try with this link will help you.
https://stackoverflow.com/questions/12021185/ios-rotate-view-only-one-view-controllers-view/15403129#1540312

Landscape mode for Xcode using storyboard

I´m making an app for a Zoo, and it is very simple, but because at fisrt I tried to make it with code and using xcode 3.2, but I had some problems so I started it with Xcode 4.3 and am trying it with the storyboards.
My question is, how could I put all the app in landscape mode? I mean I already set it in the infoplist: the initial interface orientation, and then in the .m file I changed the following:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return UIInterfaceOrientationLandscapeRight;
}
But it doesn´t work. When I add a tabbarcontroller and link it all the views become portrait. The first one if I rotate it it does give me the landscape but all the others are always in portrait, so what can I do?
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return interfaceOrientation==UIInterfaceOrientationLandscapeRight;
}
When you add tabbar controller on storyboard, in attribute inspector of tab bar you have orientation that is on inferred by default, change it to Landscape. But is better you set orientation from summary tab of project to Landscape Right. it lets your up come up on Right landscape.

Why doesn't my view display in Landscape instead of Portrait mode?

I use to define my UIViews programmatically, setting the orientation via code. I haven't touched Interface Builder in a while and I've decided to go for the new Storyboarding system.
I was pretty happy until I found out that although I have set, in the inspector pane, the appropriate view controller to "Landscape", it never displays in another mode than portrait.
I commented in and out the code in my custom view controller:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationLandscape);
}
Nothing changes.
My View Controller is itself "under" a Navigation Controller on the Storyboard, so I suspect interference, and it's only the second view in the flow, so the fact that the application itself is defined as portrait should not interfere.
I am looking for ideas to test for at this point, since the application is stripped to so little code I really can't begin to guess where to look?
What supported orientations have you specified in Info.plist? In order for a UINavigationController to support rotation, all of it's child view controllers must also support rotation to the same orientation.

Handling landscape display on iphone device rotation

I'm working on an iphone app with tab bars each one associated to a navigation controller. In one of these controllers I've a Table View showing some listing and when a row is selected another view displays specific informations and a button to see some related photos.
I'm having an issue displaying the photo view in landscape.
The photo view controller contains a UIImageView to display one photo at a time and this ImageView object size is 320x460 showing in full screen mode. To handle rotation I've added the following code:
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait || interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}
But it's not rotating and iphone simulator status bar is still in the portrait position, so not rotated too.
I've also changed the method like this:
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return YES;
}
Still no changes on device rotation. And the options in Project->Summary(Tab)->Supported Device Orientation->Desired Orientations clearly enable landscape mode (right/left).
Can you help me understand what I may be missing ?
Thx for helping,
Stephane
With a tab bar controller, it will only rotate if your view controllers for all your tabs allow the orientation. Kind of annoying, but there it is. You need to override shouldAutorotateToInterfaceOrientation in all your other view controllers too, and they need to be able to smoothly adjust to those orientations.
If it's not practical to support landscape orientations on the other view controllers, maybe you could try some hacking, for example by subclassing UITabBarController and overriding its shouldAutorotateToInterfaceOrientation to instead return YES if the current view controller returns YES. But that might get your app rejected as not conforming to Human Interface Guidelines, since you are trying to circumvent standard interface behavior.
Check if you're not in some sort of a subclassed container view controller (like your own UINavigationController or UITabBarController subclasses). If that's the case make sure it does not override shouldAutorotateToInterfaceOrientation: method.
Your looking in the wrong place: in your RootViewController.m file look for the following code:
#elif GAME_AUTOROTATION == kGameAutorotationUIViewController
//
//lots of useless comments
//
return (UIInterfaceOrientationIsPortrait(interfaceOrientation) ); //THIS LINE HERE
// return (UIInterfaceOrientationIsLandScape(interfaceOrientation) );
the line that says return (UIInterface... Portrait) is the line that determines your app's rotating capabilities. You can change this to whatever to allow you to be able to rotate completely, keep it at a certain orientation, or whatever you desire...

tabbar controller in landscape mode

I am working on a project in which I need to have the application in landscape mode. I made the changes in .plist file by setting interface orientation to landscape. I changed the orientation to landscape in the .xib files also but still when the application starts the in the simulator the tabbar controller appears in portrait mode only. Can any one please help with this.
Thanks
Note that by design, the UITabBarController will only rotate to support an interface orientation that all of its view controllers support. It will send the -shouldAutorotateToInterfaceOrientation: message to each of its view controllers and, if they all return YES, will return YES.