Orientation lock for iPhone only - ios

I have designed UI for my iOS app with wAny hRegular setting.
Now orientation works fine in iPad. But when app is running on iPhone, orientation gives a blank white screen.
Is there any way such that I can lock orientation in iPhones only and orientation is available for iPad?

You can use shouldAutorotate and supportedInterfaceOrientation UIViewController methods to lock the rotation on iPhone but not on iPad.
Simply return YES for iPad and NO for iPhone in shouldAutorotate, and you returns the allowed orientation for iPhone/iPad in supportedInterfaceOrientation.

Yes #david"mArm"Ansermot is right, I have just added the code, for quick snap:-
- (BOOL)shouldAutorotate {
UIDevice* thisDevice = [UIDevice currentDevice];
if(thisDevice.userInterfaceIdiom == UIUserInterfaceIdiomPad)
{
return YES;
}
return NO;
}
- (NSUInteger)supportedInterfaceOrientations {
UIDevice* thisDevice = [UIDevice currentDevice];
if(thisDevice.userInterfaceIdiom == UIUserInterfaceIdiomPad)
{
return (UIInterfaceOrientationMaskAll);
}
return (UIInterfaceOrientationMaskPortrait);
}

You can do this from project settings, please find the screenshots
1. http://i.imgur.com/efGrNcL.png "iPhone settings"
2. http://i.imgur.com/I25Z2cj.png "iPad settings"

Related

Support all orientations without autorotate in iPhone

The view right after the launch screen is required to be presented in the device's orientation but should not autorotate to other orientations once it is presented. I used this code :
- (BOOL)shouldAutorotate {
[super shouldAutorotate];
return YES;
}
-(UIInterfaceOrientationMask) supportedInterfaceOrientations {
[super supportedInterfaceOrientations];
return UIInterfaceOrientationMaskAll;
}
This works well for iPad but in iPhone, setting NO for shouldAutorotate results in Portrait only. Is this normal behaviour? If so how can all orientations be supported without autorotation in iPhone, for a particular view controller only?
You need to detect what orientation the device is in when you start up:
UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];
Convert that to an interface orientation:
switch (orientation) {
case UIDeviceOrientationLandscapeRight:
return UIInterfaceOrientationLandscapeLeft;
default:
return UIInterfaceOrientationLandscapeRight;
}
Now store it somewhere for global access and return that:
- (UIInterfaceOrientationMask) supportedInterfaceOrientations {
return globalOrientation;
}

How to set the Orientation of iPhone App in UIDeviceOrientationIsPortrait?

I am develop a IOS Application, I use the following code for lock the orientation of App.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
- (BOOL)shouldAutorotate
{
return NO;
}
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskPortrait;
}
If the orientation is UIInterfaceOrientationPortrait When start the App. It will lock the orientation to UIInterfaceOrientationPortrait.
But the view still show Landscape , when start the App in Landscape.
How to set the Orientation of App to UIDeviceOrientationIsPortrait for App start whether the phone is Landscape or 'Portrait`?
If you need to lock the whole app to Portrait then go to TARGETS -> General Tab -> Deployment Info
This will lock the whole app to Portrait Mode
If you only need one orientation for the entire app then go to targets, General, and deployment info. Then check portrait.
I use the following code for setting Orientation to Portrait.
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated] ;
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
//set the orientation is Portrait when the App start.
if ([[UIDevice currentDevice] respondsToSelector:#selector(setOrientation:)]) {
objc_msgSend([UIDevice currentDevice], #selector(setOrientation:), UIInterfaceOrientationPortrait );
}
}

Issue with Aviary SDK device orientation

I am trying to lunch Aviary SDK photo editor in landscape mode , but it works only on iPad !! , my app crashes on iPhone due this problem :
'UIApplicationInvalidInterfaceOrientation', reason: 'Supported
orientations has no common orientation with the application, and
shouldAutorotate is returning YES'
I tried different ways but no success :
- (IBAction)photoEditor:(id)sender {
[self displayEditorForImage:imageBG.image];
}
- (void)displayEditorForImage:(UIImage *)imageToEdit
{
//set device orientation
[AFPhotoEditorCustomization setSupportedIpadOrientations:#[#(UIInterfaceOrientationLandscapeRight),
#(UIInterfaceOrientationLandscapeLeft) ]];
AFPhotoEditorController *editorController = [[AFPhotoEditorController alloc] initWithImage:imageToEdit];
[editorController setDelegate:self];
[self presentViewController:editorController animated:YES completion:nil];
}
none of these codes worked :
1-
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return ( (interfaceOrientation == UIInterfaceOrientationLandscapeRight) ||
(interfaceOrientation == UIInterfaceOrientationLandscapeLeft) );
}
2-
-(BOOL)shouldAutorotate
{
return UIInterfaceOrientationMaskLandscapeRight | UIInterfaceOrientationMaskLandscapeLeft;;
}
3-
-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationLandscapeRight | UIInterfaceOrientationLandscapeLeft; // add any other you want
}
-(BOOL)shouldAutorotate
{
//tried NO too ,
return YES ;
}
my app is running on iOS 6 , appreciate for any help
From Aviary FAQ:
Q: How do I change the supported orientations for the editor?
A: On the iPhone form factor, the Editor is restricted to Portrait presentation only. [...]
That means what you want is impossible. The editor must run in Portrait mode.

iOS App: Window rotation always Portrait instead of Landscape

My app works only in Landscape.
Thus I set the Initial Orientation and Supported Orientation at LandScape Home Right.
However, initial launch orientation always becomes Portrait.
After navigating to next page and return, the orientation is correct.
This might be the similar question to the following, In IOS 6 on iPad, initial rotation is always portrait, after that it always rotates correctly
But the solution there is not working as the 'handleRotationFor' gives warning:
instanceMethod -handleRotationFor is not found (return type defaults to 'id')
How should I fix this error?
Please help
project Targets --> click on "Summary" tab and choose your Orientation in "Supported interfaces Orientations"
In Xcode in the files pane click on your project and then select target from right pane. Then in Summary tab see supported orientations. Only select Landscape right. Also you can implement
-(NSUInteger)supportedInterfaceOrientation {
return UIInterfaceOrientationMaskLandscapeRight;
}
in your app delegate
In Xcode under summary tab make sure portrait and upside down are not pressed down. Also Add these three functions.
// *********************
// ios6 orientation support
// *********************
- (BOOL)shouldAutorotate
{
UIInterfaceOrientation interfaceOrientation = [[UIDevice currentDevice] orientation];
if (interfaceOrientation == UIInterfaceOrientationPortrait)
{
return NO;
}
else if (interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown)
{
return NO;
}
else
{
return YES;
}
}
-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskLandscape;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
if (interfaceOrientation == UIInterfaceOrientationPortrait || interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown)
{
return NO;
}
else
{
return YES;
}
}
Check the supported orientations in the info.plist of the app. Check and set orientations in the nib file as well.
You can check orientations by using [[UIDevice currentDevice] orientation]

How to set the orientation of the app in ios automatically

I set the initial orientation of the app to UIInterfaceOrientationLandscapeRight, but when I open the app with the physical orientation of UIInterfaceOrientationLandscapeLeft, it will show the interface of UIInterfaceOrientationLandscapeRight first, then rotate to the UIInterfaceOrientationLandscapeLeft orientation.
How to make it open with the same orientation as the device?
You have to instruct your UIViewController instances on which interface orientations are supported by implementing "shouldAutorotateToInterfaceOrientation" as follows:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
if (UIInterfaceOrientationIsLandscape(interfaceOrientation)) {
return YES;
} else {
return NO;
}
}

Resources