Converting View from Landscape to Portrait? - objective-c

I have already developed the app for Landscape mode,now the client is asking to build in both Landscape and Portrait mode.
How can i convert landscape View to portrait View?
Now i am using this code for Landscape View:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft) || (interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}
Please help me....
Advance Thanks :)

Simple, to support all orientations just return YES to shouldAutorotateToInterfaceOrientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return YES;
//Or to support all but portrait upside down
return interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown;
}

Learn how to use autoresizing masks. They are simple but pretty powerful in a majority of cases.

NSPostWhenIdle is right. You just have to return yes shouldAutorotateToInterfaceOrientation. That way you can have support for all orientations. Have a look at resizing properties through XIB. that will also make your work easy.

Related

How to fix a viewcontroller's rotation?

My app uses landscape only. I fixed it via .plist's Supported interface orientations.
However, I need to use UIImagePickerController, and it only supports portrait mode. How can I rotate my app's rotation to portrait in a specific viewcontroller?
Any tips will be very helpful! Ty!
See the blog post iPhone programming: How to force your app to run in landscape mode.
ColinE, Do you mean that I should set as below?
All other viewControllers
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationLandscapeRight || UIInterfaceOrientationLandscapeLeft);
}
and set the portarit page
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

ipad rotation in iphone project

I've created a project that is targeted just for iPhone (for now) and I chose supported orientation only Portrait. On iPhone it works great, but when I launch my project on iPad my application is rotating! Actually I tried to make it a universal app and in iPad deployment info I chose supported orientation only Portrait, my app still rotated on iPad. How may I fix that?
To only support Portrait mode in your view, implement the following in each of your views:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
Also, you need to make sure that have set the Supported Device Orientations for each device as well:
You can manually set the rotation values in the view controllers by implementing this function:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return (interfaceOrientation == UIInterfaceOrientationPortrait;
}

Apple App Rejection reason [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
We found that your app does not comply with the Apple iOS Human
Interface Guidelines, as required by the App Store Review Guidelines.
Specifically, we noticed your app only supported the top up variant of
the portrait orientation, but not the bottom up variation.
While supporting both variants of both orientations, each with unique
launch images, provides the best user experience and is recommended,
we understand there are certain applications that must run in the
portrait orientation only. In this case, it would be appropriate to
support both variants of that orientation in your application, e.g.,
Home button up and down.
Addressing this issue typically requires only a simple and
straightforward code modification. However, if you require assistance,
the Apple Developer Support Team is available to provide code-level
assistance.
For more information, please review the Aim to Support All
Orientations section of the iOS Human Interface Guidelines.
Could anyone point me some code for troubleshooting that? The main app was all fine about that but now on the update my app was rejected for the second time for the same reason.
Here is my code for that
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);}
#end
But it's npt working
since you said it's an universal app everything becomes clear.
On iPads you have to support all interface orientations, especially all 180 degree variants. So if you support portrait you have to support portrait upside down too. If you support landscape left you have to support landscape right too.
On iPhones there is no need to support portrait upside down. That's the default apple puts into their UIViewController templates.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
// on iPad support all orientations
return YES;
} else {
// on iPhone/iPod support all orientations except Portrait Upside Down
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}
return NO;
}
put that into every view controller in your app.
Override shouldAutorotateToInterfaceOrientation: in your view controller(s)
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return (interfaceOrientation == UIInterfaceOrientationPortrait || interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown);
}
I'd suggest fixing "Specifically, we noticed your app only supported the top up variant of the portrait orientation, but not the bottom up variation." and testing it out of IOS5, or which ever iOS version you are putting the app out there.
Thats pretty much the only issue.
Maybe post your orientation code and we can fix it for you.
Anyways questions like this are too localized for SO. Please read the FAQ for questions that are aimed for SO. Thanks
I'm not sure how to write this below your post, but does your application rotate when you rotate the view upside down? I interpreted Apple's response as you currently do not support it.
Here is the documentation which talks about handling the view, https://developer.apple.com/library/ios/#DOCUMENTATION/UIKit/Reference/UIViewController_Class/Reference/Reference.html
Under the 'Handling View Rotations' you must support the enum types referenced here, https://developer.apple.com/library/ios/#DOCUMENTATION/UIKit/Reference/UIApplication_Class/Reference/Reference.html#//apple_ref/c/econst/UIInterfaceOrientationPortrait
I believe something like this comes in the one of the base examples, so this is more or less what they aiming for.
Best of luck, cheers.
/*
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
*/
You should accept both portrait orientations:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return UIInterfaceOrientationIsPortrait(interfaceOrientation);
}
This code accepts both UIInterfaceOrientationPortrait and UIInterfaceOrientationPortraitUpsideDown.
Edit
Now that you mention that the app is universal, then yes, Apple HIG recommend that iPad apps support all orientations (4) or at least both landscape or both portrait orientations (2).
If you want the app to support all orientations on the iPad:
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}
return YES;
If you want the app to support only portrait orientations
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}
return UIInterfaceOrientationIsPortrait(interfaceOrientation);

iOS app - changing the orientation in tabbar

In my app I have a tabbar with 5 buttons. The total app has only portrait orientation and I have set it correctly.
My problem is that when I click the second button of the tabbar, the view appears normally in portrait but when the user tilts the device I want that particular view to be get changed to landscape. Is it possible to change the tabbar position to landscape and when the other buttons are clicked all to be changed to portrait?
Else while it is tilted I have to show the view alone in landscape without the tabbar, how can I do this?
So, to be clear, you want the entire app and all views in portrait EXCEPT for the view triggered by the second tab bar button, which you want to always appear in Landscape?
if I've not confused your question, than just put the following line of code in the "viewDidLoad" method of the controller of view number 2
self.view.transform = CGAffineTransformMakeRotation(M_PI / 2);
You probably want to bite the bullet and let your project accept multiple orientations at its highest level and then decide per UIViewController which orientations are supported. This will allow the frameworks to take care of a lot of the work for you (always a good idea).
In each view's controller, override this method:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
You will want to return YES for any orientation that you want the view to support.
The four options for the interfaceOrientation parameter are:
UIInterfaceOrientationPortrait
UIInterfaceOrientationPortraitUpsideDown
UIInterfaceOrientationLandscapeLeft
UIInterfaceOrientationLandscapeRight
So for your case, you will want the view controller hosting your view and tab bar to support all of the orientations. This is how the function would look:
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations.
return YES;
}
But for a extra detail, if you wanted to support only Landscape Left and Portrait Upside Down orientation, the function would look like this:
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations.
return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft) || (interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown);
}
A UITabBar only supports rotation, if the ViewControllers of all tabs return YES at shouldAutorotateToInterfaceOrientation.
You could achieve what you want, if you let your "portrait" tabs check if they are visible (via
tabbar.selectedViewController
or
tabbar.selectedIndex
and only reply yes when they're not selected.
The user experience could be confusing though, when the user changes the tab in landscape mode
a portrait view is presented ...
try this w.r.t.: tabbar.selectedViewController
[[UIDevice currentDevice] setOrientation:UIDeviceOrientationLandscapeRight];

Rotate Interface only 180º

I just want to rotate my app aways 180º. So, I won't get it in portrait mode.
My code is like this:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return NO;
}
How can I do it?
EDIT:
I dont know why, but it stoped working. Any ideas? Even when i set return YES
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return UIInterfaceOrientationIsLandscape(interfaceOrientation);
}
That will make it so your view controller can only be in landscape orientations. UIInterfaceOrientationIsLandscape() documentation.
The return value of this method determines whether rotation to interfaceOrientation should be allowed. Therefore, you could check whether interfaceOrientation is landscape, and return YES only if so.
return UIInterfaceOrientationIsLandscape(interfaceOrientation);
I don't know why, but on of my TabBar items wasn't set with a NIB name. That's what was causing the error.