Orientation not changing on device - iphone

I have supported both LandscapeLeft and landscapeRight directions
-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationLandscapeRight;
}
But the orientation is not changing for landscapeRight. I have added observer to detect the orientation change events, those events are being called but the statusBar and navigation bar do not change for landscapeRight mode.

You've got TYPO
Instead of
UIInterfaceOrientationMaskLandscapeRight
you've got
UIInterfaceOrientationLandscapeRight

Add
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
{
UIInterfaceOrientationIsLandscape(toInterfaceOrientation);
}

Check if you have checked it orientation support on your project setting..

Related

UIImagePickerController interfaceOrientation always come up as portrit

I am trying to capture the current orientation of the UIImagePickerController being presented, and changing the overlay view's hidden property accordingly.
if([notification.name isEqualToString:#"UIDeviceOrientationDidChangeNotification"]) {
UIInterfaceOrientation orientation = self.cameraImagePicker.interfaceOrientation;
if(orientation == UIInterfaceOrientationPortrait) {
self.cameraImagePicker.cameraOverlayView.hidden = NO;
} else {
self.cameraImagePicker.cameraOverlayView.hidden = YES;
}
}
However, orientation == UIInterfaceOrientationPortrait even if I rotate the camera, but this method is called every time the device rotates.
Note: My application only supports portrait orientation according to the project file, but rotation is somehow still supported by the UIImagePickerController
Any help with this issue would be greatly appreciated!
After iOS6, apple changed the orientation API. you can try this method in your appdelegate, I hope it can help you.
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
return UIInterfaceOrientationMaskPortrait;
}

xcode - How do I keep views locked into portrait mode, but still allow one view to rotate?

I'm having a problem with device rotation. Except for ONE view, where I show a company splash screen, I want to lock all the remaining app views into Portrait display. In the project settings the supported orientations are Portrait and LandscapeLeft. In the 'Company Splash' it works fine and the view rotation is locked into LandscapeLeft no matter how I rotate the device. On all the other views when I rotate the device to the left the view alters instead of staying in portrait display. The methods are not even firing? If I remove Landscape left from the supported Orientations in the project, that screws up the 'Company Splash' view. I tried changing the shouldAutorotate return to NO, but that didn't help. Tried to work my way through the suggestions posted here, but that didn't help. If I put the following code into my AppDelegate.m, everything is locked into portrait mode and the 'Company Splash' crashes when accessed.
-(NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
return UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskPortraitUpsideDown;
}
How do I lock the view into portrait mode no matter how the device is rotated except for the one screen?
** method from the 'Company Splash' view. Again, works like it is supposed to.
-(NSInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskLandscapeLeft;
}
** methods from all the other views, which rotate out of portrait when I don't want them to
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// IOS5 Only returning that it should rotate to potrait
return (interfaceOrientation == UIDeviceOrientationPortrait);
}
-(BOOL)shouldAutorotate
{
// forcing the rotate IOS6 Only
return YES;
}
-(NSInteger)supportedInterfaceOrientations
{
// return number or enum IOS6 Only
return UIInterfaceOrientationMaskPortrait;
}
I thought maybe it might be because a UITabBarController is the root controller and I'm in a ViewController off of that? The methods are not even firing?
Add an observer to the viewDidLoad method of the view you want to rotate like this :
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter]
addObserver:self selector:#selector(orientationChanged:)
name:UIDeviceOrientationDidChangeNotification
object:[UIDevice currentDevice]];
and then set the views according the the landscape view inside the orientationChanged method like this :
- (void) orientationChanged:(NSNotification *)note{
UIDevice * device = [UIDevice currentDevice];
switch(device.orientation)
{
case UIDeviceOrientationPortrait:
break;
case UIDeviceOrientationPortraitUpsideDown:
break;
case UIDeviceOrientationLandscapeLeft:
break;
case UIDeviceOrientationLandscapeRight:
break;
default:
break;
};
}
Slap this method into the view controller you want locked in a certain orientation.
-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskLandscape;
}
just change to the orientation you want (the above locks it in landscape)
maybe u should allow all orientations, and lock portrait orientation in each class except company splash with
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
if (interfaceOrientation == UIInterfaceOrientationPortrait) {
return (interfaceOrientation == UIInterfaceOrientationLandscapeRight);
} else {
return (interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}
}

How to set initial interface orientation?

My application always launches in landscape mode with the home button on the left side. If the home button on the right side it rotates. How do i make it opposite? I tried setting different values into info.plist file for initial interface orientation key but it didn't work. I tried switching order of values in this method:
- (NSInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskLandscapeRight | UIInterfaceOrientationMaskLandscapeLeft;
}
but it didn't work neither. How do i do that?
For IOS 5 and 5.1 :
Try to set (BOOL)shouldAutorotateToInterfaceOrientation in your view controllers, it works for me.
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {
return toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft || toInterfaceOrientation == UIInterfaceOrientationLandscapeRight;
}
If you are using storyboards you can also set your initial and other viewcontrolers to landscape mode :
For IOS 6:
your (NSInteger)supportedInterfaceOrientations should be (NSUInteger) , I am not sure though I never use it.
// Only used by iOS 6 and newer.
- (BOOL)shouldAutorotate
{
//returns true if want to allow orientation change
return TRUE;
}
- (NSUInteger)supportedInterfaceOrientations
{
//decide number of origination to supported by Viewcontroller.
return return UIInterfaceOrientationMaskLandscape;
}

Programmatically change device orientation in iPhone

I have navigation based app, when I click on any row in root view, the next view should come in Landscape mode.
I am not able to find a proper way to implement this. What I tried is:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return UIInterfaceOrientationIsLandscape(interfaceOrientation);
}
But this is not working. The view should open only in Landscape mode (not when user rotate it).
My sandbox app:
https://github.com/comonitos/programatical_device_orientation
The solution is easy:
in interface (h file) :
BOOL rotated;
in implementation (m file):
1. rewrite
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return rotated;
}
2 call [self setup]
-(void) setup {
rotated = YES;
[[UIDevice currentDevice] setOrientation:UIDeviceOrientationLandscapeLeft];
rotated = NO;
}
Try designing your view in landscape mode and in it's view controller, and in
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
.....
}
return No for portrait orientation and YES for landscape orientation
This will display your view in landscape mode.
you can force your Device to change Orientation.......using magic line in View will Appear
[[UIDevice currentDevice] setOrientation:UIDeviceOrientationLandscapeRight];
All the Best..
Here is some code from my landscape-view based app:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation{
if (interfaceOrientation == UIInterfaceOrientationLandscapeRight || interfaceOrientation == UIInterfaceOrientationLandscapeLeft){
return YES;
}
else {
return NO;
}
}
Put this in a landscape-based viewcontroller to have it display only in landscape mode and to switch between landscape left and landscape right. You will also need your xib to be landscape based.

Remove ability for portrait orientation for app in iPhone SDK

Is there a way where I can only allow my app viewable in landscape mode? I've managed to default the application's orientation to landscape, however in the iPad simulator, when I do Command->Arrow, the application rotates to portrait. I've removed the listings in the plist under "Supported interface orientations" for both of the Portrait entries, however that doesn't seem to've changed anything.
Any idea?
In your view controller, there's a delegate method for this:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
return ((interfaceOrientation == UIInterfaceOrientationLandscapeLeft) ||
(interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}
Do a project find for "autorotate", and edit the methods you'll find accordingly.
I believe you need tell the view that the specified orientation is not supported
http://developer.apple.com/iphone/library/documentation/UIKit/Reference/UIViewController_Class/Reference/Reference.html#//apple_ref/occ/instm/UIViewController/shouldAutorotateToInterfaceOrientation:
Actually it is
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft) ||
(interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}
Things have changed with some updates. Currently, you'll simply need to add the following method:
-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskLandscape;
}
that will only allow landscape. Turn the phone all you like and it will only stay in either left or right landscape. Have fun :)