i am having tabBarController.It is having 3 viewControllers.I want to support landscape mode in only one of these viewControlers.and other 2 view controllers in potrait mode.How to achive this.
In the view controller you want to support landscape simply return YES to
(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
Of course I'm assuming your implementation is creating a view controller for each view
Ya i am having view for each viewController.But i want to support landscape in only one view and rest all in potrait mode.Even i am returning YES in (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
if interfaceOrientation is landsape in view which i want to support and in rext views i am returning NO in this method if interfaceOrientation is landScape mode.
Related
I have a UITabBar application with embedded UINavigation for some of the views. On one specific navigationview I am displaying graphs/charts and it would be better to display them in landscape as if the iPhone was rotated to the left or right. The rest of the app is better suited to portrait. So I want to "force" the views containing graphs to load in landscape regardless of how the user has the device physically rotated. I've tried:
#pragma mark - Rotation
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft);
}
But this does not seem to do anything to the view. If I select the "Landscape Left" icon in the "Supported Interface Orientations" for my target then it allows the entire app to re-orientate on rotation of the device. Is there a way to lock my app in portrait for all normal views and lock in landscape for my views containing graphs such that the app ignores the actual device orientation?
You are right. In tab bar applications it is not the shouldAutorotateToInterfaceOrientation: method of the individual view controllers being called. Only the tab bar controller's shouldAutorotateToInterfaceOrientation is called to determine whether and how the views can be oriented.
However, the individual view controllers should implement shouldAutorotateToInterfaceOrientation accordingly anyway. Those methods are still used to determine the orientation of animation effects when pushing or pulling a view controller.
I never tried the following myself: You could try subclassing the tab bar controller and respond to shouldAutorotateToInterfaceOrientation accordingly depending on which view is currently shown to the user. But I fear that Apple has good reasons for forcing us to support the same orientations for all views within a tab bar app.
Firstly I am using iOS 6 SDK.
I am using a custom TabBar Controller.
and controlling the orientation of that TabBar Controller by the below set of codes
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// You do not need this method if you are not supporting earlier iOS Versions
return [self.selectedViewController shouldAutorotateToInterfaceOrientation:interfaceOrientation];
}
- (NSUInteger)supportedInterfaceOrientations
{
return [self.selectedViewController supportedInterfaceOrientations];
}
- (BOOL)shouldAutorotate
{
return YES;
}
And the view controller should contain
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)orientation {
return UIInterfaceOrientationIsLandscape(orientation);
}
This is what I did and was able to lock a view to landscape or portrait (in my case). To force may be you can put a alert view stating the user to turn the device to landscape and show him the graph. Just a suggestion.
Try it in particular ViewController in which you need to required in landscape mode:
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight );
}
I know how to control the autorotation of a UINavigationController, but I would like to programmatically rotate a UINavigationController: the navigation bar, and view stack, to a specified UIInterfaceOrientation value, regardless of the current device orientation.
Is that possible?
Thanks
First, setup your application/view controller to use only one specific orientation (that is, block automatic rotations).
Then you can rotate the underlaying view layer (UIView.layer of type CALayer) using an affine transform.
Implement the - shouldAutorotateToInterfaceOrientation: in your view controllers insided the UINavigationController, only return YES on your desired orientation. e.g., the UINavigationController only display on landscape:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return UIInterfaceOrientationIsLandscape(interfaceOrientation);
}
May this helps.
I have application that uses landscape right orientation.
In view controllers I use:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}
But, If user locks iphone or ipad to portrait orientation, screen is displayed
as portrait, not landscape. Also, in info.plist file I defined only Right Landscape orientation as
supported one.
Try setting the UIInterfaceOrientation key in your Info.plist to UIInterfaceOrientationLandscapeRight. That should force landscape right orientation on launch.
The problem was in function viewDidLoad where another view controller is pushed into navigation stack immediately. If pushing action is delayed then landscape rotation will start and proceed, and also desired view controller will be pushed properly with landscape orientation.
When I navigate from one view to another view, I want to open the view in portrait view only.ie I am navigating from a first view (landscape) to second view. I want the second view to always be open in portrait view.In my case when I launch in landscape, the view is in portrait but the device is in landscape mode. The output I expected was if I open the view in portrait and and on rotating it to landscape with no rotation.
EDIT:
If you open the app in portrait and if you given auto-rotate as NO.Then if you rotate the device to landscape,then there will be no rotation in output.I want the same effect when loading a view initially in landscape.
I'm pretty sure you cannot use setOrientation anymore, since it is deprecated and apps have been declined for using it.
This may be an option for you:
http://www.iphonedevsdk.com/forum/iphone-sdk-development/33548-alternative-setorientation.html
It rotates the view using a transformation.
Okay so what you want to do is edit one of the functions in the view file. You want to set;
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations.
return YES;
}
From return YES to return (interfaceOrientation == UIInterfaceOrientationPortrait);
Then your view should only be in potrait.
Is it possble to show a map in landscape mode?
Yes.
The easiest way to accomplish it is to put your map view in a view controller that you then present in some way. Whatever orientations the view controller then supports will cause the hosted map view to rotate to automatically.
In your view controller you'd implement this method:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return UIInterfaceOrientationIsLandscape(interfaceOrientation);
}
That example handles both lanscape orientations. As long as your map view is set to autoresize correctly in your NIB file it should all just work.