How to update my UIViewController to current orientation when use pushViewController? - iphone

i have use this code but it is Private API ,apple also reject!
[[UIDevice currentDevice] setOrientation:UIInterfaceOrientationLandscapeRight];
if i rotate my device in Landscape then open my Application it will present as Portrait mode, i need to rotate my device to another orientation then it will update.
how to update it to correct orientation when call UIViewController?

You should use the follow code at your UIViewController class:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}
if u need to update orientation at runtime then u have to return other constant
return (interfaceOrientation == UIInterfaceOrientationPortrait);

Related

shouldAutorotateToInterfaceOrientation won't respect my wishes

(Using Storyboard)
I'm trying to make one of my ViewController Subclasses support more than just portrait view.
I've added in
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return ((interfaceOrientation == UIInterfaceOrientationLandscapeLeft) || (interfaceOrientation == UIInterfaceOrientationPortrait));
}
but it doesn't seem to do anything. I've got all orientations except upsidedown supported in my plist, and added the shouldautorotate to allow only portrait in the viewcontrollers that I want.
The method you're looking for in ios6 is - (NSUInteger)supportedInterfaceOrientations
This essentially replaced shouldAutorotate. Use it in conjunction with shouldAutorotate.

Navigation Controller in landscape with Storyboard [iPhone]

I'm working with Navigation Controller in my storyboard, but my application is always in portrait format when I put the simulator in landscape. Why? =(
Change
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
To
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}
Also make sure in your project settings you have 'Supported Device Orientations' set to allow Landscape.

How to disable portrait orientation on UINavigationController rootViewController

I have a class, HomeView, as the rootViewController of a UINavigationController on my iPad application. Only landscape orientation is set in the info.plist file and HomeView does not implement shouldRotateToInterfaceOrientation:, however the view is rotating for both orientations while the simulator is rotating.
How do I only use the landscape orientations in my UIViewController?
If you do not implement shouldAutorotateToInterfaceOrientation: the runtime will call the method on the Super class, UIViewController.
Instead you should respond appropriately to the method with the orientations you want to rotate to:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
BOOL shouldAutorotate = NO;
if (interfaceOrientation == UIInterfaceOrientationLandscapeLeft
|| interfaceOrientation == UIInterfaceOrientationLandscapeRight) {
shouldAutorotate = YES;
}
return shouldAutorotate;
}
Take a look at the UIInterfaceOrientation reference page and the UIViewController's shouldAutorotateToInterfaceOrientation: reference page for more information.
You shouldn't remove the shouldAutorotateToInterfaceOrientation method; that will not stop the interface from rotating, it will only not execute any code that you could have in that method. You should instead try something like this (assuming that you don't ever want the interface to rotate):
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return NO;
}

Supported orientations not limiting actual orientations

I have an iPad game that I only want to see in landscape view. I have selected the landscape view from the target's summary and have the code
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return YES;
}
in my first viewcontroller which is added to a navController. But the only effect that I can see by changing the target's orientations is not how it can be rotated but rather what direction it is first loaded in. Does anyone have any ideas? Thanks!
Try this:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}

Allow only LeftLandscape and RightLandscape orientation

How can I made my app to allow only the landscape orientation but both (left and right)?
so if I rotate 180° the app will be rotate but if I rotate in portrait the app doesn't rotate?
thanks
Try adding this to your UIViewController:
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft ||
interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}
You can learn more about this here: UIViewController class reference