Rotate Interface only 180º - objective-c

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.

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);
}

Set different supportedInterfaceOrientations for different UIViewControllers

So, as by the question, I use the following code to set userinterfaceOrientation for the viewcontroller.
- (BOOL) shouldAutorotate
{
return YES;
}
-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskPortrait;
}
I tried setting UIInterfaceOrientationMaskAll for another viewController.
Prior, I checked all the items for Supported interface orientations in the info-plist. Both the viewControllers returned true(as set in the info-plist) for all the orientations and didn't obey the above code. IT worked even in the absence of the above code. Is there anyway to restrict certain Supported interface orientations for particular classes? I made it working for the pre - iOS6 versions by following this link.
I was able to accomplish this by placing my supported orientation logic in a custom UINavigationController. I then segue to the relevant view controller.
#implementation PortraitNavigationController
- (NSUInteger)supportedInterfaceOrientations{
return UIInterfaceOrientationMaskPortrait;
}
...
I'd say implement your shouldAutorotateToInterfaceOrientation: on every view controller to make it return only YES for those orientations you wish to support.

Converting View from Landscape to Portrait?

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.

Orientation of a navigationController in a TabBarController doesn't work like it should

This is the situation
The label-viewcontroller is able to change orientation, the viewcontroller with the "ok?"-button is only able to be viewed in portrait. This works PERFECT, when I'm at the label-viewcontroller, in landscape, and I go back to the "ok?"-viewcontroller it automatically switches to portrait. like it should.
But the thing is, I want the "Ok?"-Viewcontroller to be viewed in landscape, not in portrait. When I do this, it doesn't work annymore... When I'm in the label-viewcontroller and i go back it doesn't change to landscape...
So...
When I put the "ok?"viewcontroller in portrait it works, but when I put it in landscape it doesn't, why is this and how can I solve this?
Works, but I don't need it this way.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return UIInterfaceOrientationIsPortrait(interfaceOrientation);
}
Doesn't work but I need it to work.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return UIInterfaceOrientationIsLandscape(interfaceOrientation);
}
The label-viewcontroller is simply.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return YES;
}
and the TabBarController.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return [self.selectedViewController shouldAutorotateToInterfaceOrientation:interfaceOrientation];
}
sorry for the bad english

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];