What are the methods for Orientation in iOS 7? - ios

In my Application one of the ViewController is need to be supported from portrait to landscape/landscape to portrait, and remains support to portrait only I achieved this in Xcode 4.6 with iOS 6 but when I run my code in Xcode 5 with iOS 7 those methods are not being called. Is there any methods deprecated in iOS 7. If yes what are those methods?
I have created a sub class for UINavigationController and below is the my code which is working fine in iOS 6.
-(BOOL)shouldAutorotate
{
return [[self.viewControllers lastObject] shouldAutorotate];
}
-(NSUInteger)supportedInterfaceOrientations
{
// return [[self.viewControllers lastObject] supportedInterfaceOrientations];
return [[self topViewController] supportedInterfaceOrientations];
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return [[self.viewControllers lastObject]
preferredInterfaceOrientationForPresentation];
}
Please help me. Thanks in advance.

Have you checked this mark these all device orientations

oky, in the viewcontroller that needs to support landscape use the following code
- (BOOL)shouldAutorotate
{
return YES;
}
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskLandscape;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return UIDeviceOrientationLandscapeLeft; //which side u want weather left or rite
}
and view controllers that supports portrite
- (BOOL)shouldAutorotate
{
return NO;
}
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskPortrait;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return UIDeviceOrientationPortrait;
}
you hav to set the supported orientations as #Gurpreet said ..
try this, hope this helps u :)

Related

Orientation Portrait in navigation Controller

I try to force navigationController to be in orientation Portrait on my application. But I solved the problem by subclassing the navigationController class by this way :
- (BOOL)shouldAutorotate
{
if (self.visibleViewController && [self.visibleViewController respondsToSelector:#selector(shouldAutorotate)])
{
return [self.visibleViewController shouldAutorotate];
}
return YES;
}
- (NSUInteger)supportedInterfaceOrientations
{
if (self.visibleViewController && [self.visibleViewController respondsToSelector:#selector(supportedInterfaceOrientations)])
{
return [self.visibleViewController supportedInterfaceOrientations];
}
return UIInterfaceOrientationMaskPortrait;
}
So all my controller inherits to this. But my problem is when I start my application with my iPhone in landscape mode, my viewController not respect the interfaceorientationlandscape. But when I turn my iPhone it's works and not change if the orientation changes.
I search how can I force my orientation to change if is not in portrait in viewDidLoad or if possible in viewDidAppear.
If you want to have this app-wide
You can get there by clicking on the corresponding menu item:
Otherwise if you want to set this for one ViewController only
- (BOOL)shouldAutorotate {
return YES; // or NO
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
return UIInterfaceOrientationLandscapeLeft; // or UIInterfaceOrientationLandscapeRight or UIInterfaceOrientationPortrait
}
- (NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskLandscape; // or UIInterfaceOrientationMaskPortrait
}

Autorotation in iOS 6 & iOS 7

I want to support the autorotation in iOS 6 and 7. In my project I have a UITabBar with 4 ViewControllers. Only one ViewController of them should support the autorotaion to Portrait and Landscape. The other views should support only the Portrait style.
I hope you have an idea how to implement this function. shouldautorotatetointerfaceorientation doesn't work in iOS 7 :(
I added a UITabBarConntroller to control the autorotation
- (BOOL)shouldAutorotate {
return YES;
}
- (NSUInteger)supportedInterfaceOrientations {
if (self.selectedIndex == 1)
return (UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationPortrait);
else
return UIInterfaceOrientationMaskPortrait;
}
Maybe there is a way to change the Orientation manual when the View with the index 1 did disappear??
I hope you have a solution!
Set the orientations settings like this:
In UITabBarController:
-(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
{
if (self.selectedViewController)
return [self.selectedViewController supportedInterfaceOrientations];
return UIInterfaceOrientationMaskPortrait;
}
-(BOOL)shouldAutorotate
{
return YES;
}
Open project
Go to the General tab
Under orientation options check all checkbox orientation that you need to support
Go to the implementation of first view controller and add this code:
- (BOOL)shouldAutorotate
{
return YES;
}
Also for supporting iOS 6 implement method:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationMaskAll);
}
Go to all other view controllers that are represented your tabs and set:
- (BOOL)shouldAutorotate
{
return NO;
}
Also for supporting iOS 6 implement method:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
Check this link as well

Lock the orientation for only the main UIViewController - iOS

I would like to know how I could lock the orientation for my main View Controller but allow my users to rotate to landscape for all the View Controllers?
Thanks in Advance!
For MainViewController:
-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskPortrait;
}
Other ViewControllers
-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskLandscape;
}
- (NSUInteger)supportedInterfaceOrientations {
UIInterfaceOrientationMaskPortrait
}
The default for iPad is
UIInterfaceOrientationMaskAll
while the iPhone default is
UIInterfaceOrientationMaskAllButUpsideDown
you shouldn't need to implement anything else on your other view controllers
This may help you..
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
-(BOOL)shouldAutorotate{
return NO;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation{
return UIInterfaceOrientationPortrait;
}

restricting autorotation on certain views

my app contains two table view controllers. in the first one i want the view to be able to be rotated left and right (in addition to the portrait mode), however in the second table view controller ( which i navigate to after tapping a cell from the first table) i want it to only be viewed in portrait mode. i tried this code but it didn't work, it keeps on rotating.
- (NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskPortrait;
}
- (BOOL) shouldAutorotate {
return NO;
}
note: i did actually enabled the left/right/portrait orientation from the Summary tab of the project target. any fix?
Create a category for UINavigationController which include the following methods:
(Works both for iOS 6 and iOS 5)
- (BOOL)shouldAutorotate
{
return self.topViewController.shouldAutorotate;
}
- (NSUInteger)supportedInterfaceOrientations
{
return self.topViewController.supportedInterfaceOrientations;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {
return [self.topViewController shouldAutorotateToInterfaceOrientation:toInterfaceOrientation];
}
Then implement these methods in your controllers
First:
- (BOOL)shouldAutorotate {
return YES;
}
- (NSUInteger)supportedInterfaceOrientations {
if (RUNNING_IPAD) {
return UIInterfaceOrientationMaskAll;
}
else {
return UIInterfaceOrientationMaskAllButUpsideDown;
};
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {
if (RUNNING_IPAD) {
return YES;
}
else {
return toInterfaceOrientation != UIInterfaceOrientationMaskPortraitUpsideDown;
}
}
And Second:
- (BOOL)shouldAutorotate {
return NO;
}
- (NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskPortrait;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {
return NO;
}
The rotation settings of the project should look like:
Actually i found a solution for my problem:
-(BOOL)shouldAutorotate{
return YES;
}
-(NSInteger)supportedInterfaceOrientations{
return UIInterfaceOrientationMaskPortrait;
}
this will restrict a view to portrait even if you toggled the left/right orientations in the Summary tab of the project's Traget.

preferredInterfaceOrientationForPresentation must return a supported interface orientation

This error doesn't make sense, as the preferred orientation UIInterfaceOrientationLandscapeRight is returned by the supported orientation
//iOS6
-(BOOL)shouldAutorotate
{
return NO;
}
-(NSUInteger)supportedInterfaceOrientations
{
return (UIInterfaceOrientationLandscapeRight | UIInterfaceOrientationLandscapeLeft);
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return UIInterfaceOrientationLandscapeRight;
}
Error :
Terminating app due to uncaught exception
'UIApplicationInvalidInterfaceOrientation', reason:
'preferredInterfaceOrientationForPresentation must return a supported
interface orientation!'
Your code should look like this:
-(BOOL)shouldAutorotate
{
return NO;
}
-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskLandscape;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return UIInterfaceOrientationLandscapeRight;
}
Also, make sure in your Info.plist you have set the correct orientations for you app because what you return from supportedInterfaceOrientations is intersected with the Info.plist and if it can't find a common one then you'll get that error.
supportedInterfaceOrientations is only called, if shouldAutorotate is set to YES
- (BOOL)shouldAutorotate
{
return YES;
}
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskLandscape;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return UIInterfaceOrientationLandscapeRight;
}
The easiest approach for me, is only to set the Info.plist
If you like to support iOS 5 use this code in your view controllers.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return UIInterfaceOrientationIsLandscape(interfaceOrientation);
}
Those are the wrong enums for supportedInterfaceOrientations. You need to use UIInterfaceOrientationMaskLandscapeLeft, etc (note the word mask in the middle)
from the documentation:
-(NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskLandscapeRight | UIInterfaceOrientationMaskLandscapeLeft;
}
Note that the correct orientation is "Mask"!
Did you try this?

Resources