Supported orientation madness - iphone

I know this is the most commonly asked question and trust me I have tried every kind of combination to make this happen and went through most posts here on stack overflow.
I have a UINavigationController called v1ViewController and what I am trying to do is when it is shown to the user I just want it to either show in portrait or portrait-up-side-down modes, no landscape even if the user rotates the device in landscape it shouldn't do anything.
NOTE: I did highlight all options in Xcode for supported interface orientations as in one of my other view controller I need to show user something in both landscape and portrait modes but for this UINav Conrtoller I want it to just remain in portrait modes.
The code I have for iOS 5.0 work just fine without a problem.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
if (interfaceOrientation == UIInterfaceOrientationPortrait)
{
return YES;
}
else if (interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown)
{
return YES;
}
else
{
return NO;
}
}
the headache I have is with iOS 6. No matter what I try and do it still lets the user rotate the bloody thing in landscape (see code and screenshots)
// *********************
// iPhone 5 orientation support
// *********************
- (BOOL)shouldAutorotate
{
UIInterfaceOrientation interfaceOrientation = [[UIDevice currentDevice] orientation];
if (interfaceOrientation == UIInterfaceOrientationPortrait)
{
return YES;
}
else if (interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown)
{
return YES;
}
else
{
return NO;
}
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return UIInterfaceOrientationPortrait;
}
-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskPortraitUpsideDown;
}

You need to ensure you override the base UINavigationController and assign a custom class to it(not just the viewController that is the subview for the UINavController..ie the view contained below the navigationBar). Inside the UINavigationController, return NO on shouldAutoRotate.

Related

iPhone interface orientation change not returning to portrait orientation

So I have a view that I present modally when the interface orientation changes to landscape. However when the orientation returns to portrait and the modal view dismisses itself, the tableview from the initial view remains in landscape orientation (this table view must be only in portrait orientation)
Here is the code :
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return ((interfaceOrientation == UIInterfaceOrientationPortrait) || (interfaceOrientation == UIInterfaceOrientationLandscapeLeft) || (interfaceOrientation == UIInterfaceOrientationLandscapeRight) );
}
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
if ((toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft) || (toInterfaceOrientation == UIInterfaceOrientationLandscapeRight)) {
[self performSegueWithIdentifier:#"showCatChart" sender:self];
}
if (toInterfaceOrientation == UIInterfaceOrientationPortrait) {
[self refreshTableView];
}
}
I tried to refresh the tableview but that doesn't make it portrait again ...
this could be from the view hierachy ...
NavigationController->tableView (only portrait)->tableview->landscapeViewModalController
With iOS 6, you need to implement the following:
- (BOOL)shouldAutoRotate {
return YES;
}
- (NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskAll;
}
In your AppDelegate, you need to change the following:
[self.window addSubview:viewController.view];
to
[self.window setRootViewController:viewController];
Also, keep your current code if you want to support previous versions of iOS.
Use the following in appdelegate.
[self.window addsubview:viewcontroller];
This alone will solve your orientation problem.

Supporting orientations IOS

Hello i want to support portrait, home button up and down in my application how can i do that?
i go to my project settings check those two
and i add the code below
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return UIInterfaceOrientationIsPortrait(interfaceOrientation);
}
I also tried
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait || interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown);
}
but none seems to work
any help
Try this
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation{
if((interfaceOrientation == UIInterfaceOrientationPortrait) || (interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown)){
return YES;
}
return NO;
}
If it still doesn't work, you can try this (just for the sake of testing)
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation{
return YES;
}
if this doesn't work, either you are not messing with the right view controller, or the parent/root view controller has rotation disabled (returning NO in shouldAutoRotate method of the rootVC)

iPad application having landscape mode only, issue

if (interfaceOrientation == UIInterfaceOrientationPortrait) {
return NO;
} else if (interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown) {
return NO;
} else if (interfaceOrientation == UIInterfaceOrientationLandscapeLeft) {
NSLog(#"Landscape left detected!");
return NO;
} else if (interfaceOrientation == UIInterfaceOrientationLandscapeRight) {
NSLog(#"Landscape right detected!");
return YES;
}
I am trying to implement an iPad app having landscape mode only. I set the Supported interface orientations as Landscape right mode in info.plist. WHen the application is started, the view is in Landscape mode itself. But when i added another view, such as Home view, after login, view is not rotated as landscape. It was in portrait mode. In the xib file also, i set it as landscape. I have included the above code in both Login and Home view controller.
But the home view is not rotating after login.
First you dont have to write checks for each and every orientation. You can achieve this by simply using the following code in your viewController's shouldAutorotateToInterfaceOrientation method
return (interfaceOrientation == UIInterfaceOrientationLandscapeRight);
Second can you provide more details on how actually you are adding more views. It will be more helpful to find the problem.
do this in each view controller
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight)
}

Issue on UIOrientation in ipad

I'm developing the app for all the orientations in Ipad....But during the development I did only for landscape mode..But nw I want to change to all the possible orientations... Here I got some problem....
Here is the code...
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
//return YES;
return (interfaceOrientation == UIInterfaceOrientationLandscapeRight || UIInterfaceOrientationPortrait);
}
- (void) willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
[self adjustViewsForOrientation:toInterfaceOrientation];
}
- (void) adjustViewsForOrientation:(UIInterfaceOrientation)orientation {
if (orientation == UIInterfaceOrientationLandscapeLeft || orientation == UIInterfaceOrientationLandscapeRight)
{
\\Here I did my stuff..
}
else if (orientation == UIInterfaceOrientationPortrait || orientation == UIInterfaceOrientationPortraitUpsideDown)
{
\\Here I did my stuff..
}
}
The problem is,When the simulator is launched and if itz in the landscape mode,I got the proper size of the views,but if the simulator is in potrait mode I can't get what I want... If I change the orientations of simulator I get the correct size of the views...
This was the same problem that was facing.
And i solved it by doing this:
First change this function:
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return YES;
}
and then in the viewDidLoad function you can check whether the device is in landscape or in Portrait.
-(void)viewDidLoad
{
if (UIInterfaceOrientationIsLandscape(self.interfaceOrientation))
{
//landscape view code
}
else
{
//portrait view code
}
}
hope this will help

How to disable any autorotation?

I am trying to code for calling Landscape screen from Portrait screen.
When current screen orientation is Landscape, it would be doesn't allow any autorotation.
I've tried the following code :
// Override to allow orientations other than the default portrait orientation.
/*- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}*/
- (void)viewDidLoad {
[UIApplication sharedApplication].statusBarOrientation = UIInterfaceOrientationLandscapeRight;
CGAffineTransform landscapeTransform = CGAffineTransformMakeRotation(degreesToRadian(90));
landscapeTransform = CGAffineTransformTranslate(landscapeTransform, +90.0, +90.0);
[self.view setTransform:landscapeTransform];
}
But above code is allowing UIInterfaceOrientationLandscapeRight.
How to disable any autorotation ?
Thanks in advance.
Do you want start your application in the landscape mode or not?
In all case you must override the shouldAutorotateToInterfaceOrientation method.
But if you want start your application in the Portrait mode and then go to the Landscape mode you can add a static boolean to know if you must stay in the landspace mode or not.
You code must look something like that:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
if(isInPortraitMode) {
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationLandscapeRight);
} else {
if(interfaceOrientation == UIInterfaceOrientationLandscapeRight) {
isInPortraitMode = YES;
}
return YES;
}
}
- (void)viewDidLoad {
isInPortraitMode = NO;
//...
}