Set keyboard orientation only (iOS 6) - ios

my app has been working fine until I've tried making some changes using the ios 6 SDK
The app runs in portrait mode 99% of the time. This has been constrained by only allowing portait mode to be available in the info.plist
There is one view controller which needs to be shown in landscape mode. This is achieved "manually" by simply rotating the view by 90 degrees, like so:
self.view.transform = CGAffineTransformMakeRotation(3.14159/2);
This still works fine in iOS 6.
However, this view controller has some text fields. When the user taps one it shows the keyboard. Since I've only rotated the view (and not actually changed the orientation of the device), the keyboard comes out in portrait mode, which is no good.
In previous versions of iOS, I set the orientation of the status bar to be landscape, and as a byproduct, this would set the keyboard to be landscape as well, like this:
[[UIApplication sharedApplication] setStatusBarOrientation: UIInterfaceOrientationLandscapeRight animated:NO];
However, this has stopped working for iOS 6.
I have read a million stack overflows trying to get this to work, but still have no luck.

Changing the keyboard orientation and transform is an difficult part and not a good solution(especially when it changes status bar orientations).
Better solutions is to allow application to support all orientations.
Implement the Orientation delegates inside your ViewControllers asper the rotation support.
For Supporting only Landscape
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return interfaceOrientation == UIInterfaceOrientationLandscapeLeft
|| interfaceOrientation == UIInterfaceOrientationLandscapeRight ;
}
- (BOOL)shouldAutorotate
{
return NO;
}
For Supporting only Portrait
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
- (BOOL)shouldAutorotate
{
return NO;
}
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskPortrait;
}

Related

Landscape orientation for one view controller ios

I want to show one view controller in both orientation in iPhone. And when the screen is opening the preferred orientation should be portrait only. Then according to the device orientation it'll rotate. I found some solution and the screen is rotating too. But when I'm entering the screen it is auto rotating to landscape and than I've to manually rotate it to portrait.
Is there a simple solution to this problem?
You should implement preferredInterfaceOrientationForPresentation and
supportedInterfaceOrientations like:
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return UIDeviceOrientationPortrait;
}
//You don't actually need to implement this as UIInterfaceOrientationMaskAllButUpsideDown is the default for iPhone
- (UIInterfaceOrientationMask)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskAllButUpsideDown;
}

Force UiInterfaceOrientation from Landscape to Portrait?

I know may be it's a duplicate question, but I tried many answers described here and I can't get it working from hours.
I'm working on an application for IOS 6 and IOS 7, just I need to move from my first viewController "A" which is on Landscape orientation, to a second viewController "B" which is on Portrait orientation.
I configured the project to enable all desired orientation, set the "appropriate" code, but still get the second view displayed vertically on a landscape orientation..
here is the code I set for first controller :
- (BOOL)shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}
-(BOOL)shouldAutorotate
{
return YES;
}
-(NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskLandscape ;
}
Plz help.
If you use the UINavigationViewController methods(pushViewController:animated: and popViewControllerAnimated:), the views will inherit the previous view's orientation.
On the other hand, if you use presentModalViewController:animated: and dismissModalViewControllerAnimated: methods, everything works perfectly.
Also here is a sample project which is also changing orientation as required by you

Application always launch in Landscape Left

In my application, supported orientations are Landscape Right & Landscape Left. Its single screen application. In ViewController I added following code to restrict orientation.
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskLandscape;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return UIInterfaceOrientationIsLandscape(interfaceOrientation);
}
-(BOOL)shouldAutorotate
{
return YES;
}
My Problem is whenever app launches in Landscape Left. If device position Landscape Right, then app view rotate in 180 degree then app starts working in Landscape Right.
There is no issue if device position is Landscape Left.
Note: I am testing application on iPod 5.
EDIT:
After some observations, If you are supporting only Landscape (i.e Landscape Right & Landscape Left), then you will face this problem. Application will always open in orientation which listed first in plist (In my case that is Landscape Left).
I Closed this issue by removing Landscape Left orientation support. If any one have solution for this please share.
Thanks for help.
I had the same problem, setting the 'Initial interface orientation' to UIInterfaceOrientationLandscapeLeft in the plist didn't work, nor did returning it in preferredInterfaceOrientationForPresentation in the view controller.
What solved this for me is reordering the 'Supported interface orientation' array in the plist to have my desired initial orientation as the first item in the array.
Did you checked the orientation settings in your General settings of the project in XCode.
Replace your method shouldautotrotatetointerfaceorientation to
- (BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return ((interfaceOrientation == UIInterfaceOrientationLandscapeLeft) || (interfaceOrientation == UIInterfaceOrientationLandscapeRight));
}

UIDevice orientation not working as expected

I am having a problem with device orientation. I have an iPhone app that has some views, all of them should not rotate except one. So I take a look inside Info.plist; I select two device orientations, portrait and lanscape, and in the views I dont want to rotate so I put this.
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return NO;
}
but all the views rotate. Even with these lines in them. If change Info.plist to support no portrait. It works ok, just the view that I want to rotate, I put
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return YES;
}
And it does not work. I use iOS 6. Also tried
- (NSUInteger)supportedInterfaceOrientations
- (BOOL)shouldAutorotate
Try specifying exactly the orientations you would like the view to rotate to. For instance, if you want portrait only use this:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
For rotating to all views, you can still use YES, although this will allow it to rotate to the upside down view which isn't always desired. To get both landscape orientations and right side up portrait, use this:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}

iPad orientation behaviour inconsistent - changes on each launch?

I have a very strange problem that I am as yet unable to diagnose.
In my iOS app (it's a universal binary), when I run on iPad 4.3, the orientation at launch is inconsistent.
The app delegate adds a splash screen (UIViewController) to the main window, then removes it and adds the app's primary view. It is this primary view which is the issue - approximately half of the time, it loads up correctly in landscape orientation, the other half it loads the view in portrait (though both the status bar and keyboard are correctly in landscape).
I'm at a bit of a loss as to why the orientation at launch is changing, when I am making no changes to the code or the simulator/device orientation.
I have UIInterfaceOrientationLandscapeLeft and UIInterfaceOrientationLandscapeRight set as the only supported orientations for iPad in the Info.plist and every view controller is using the following:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
// The device is an iPad running iPhone 3.2 or later.
if (interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight) {
return YES;
}
} else {
// The device is an iPhone or iPod touch.
if (interfaceOrientation == UIInterfaceOrientationPortrait) {
return YES;
}
}
return NO;
}
Can anyone help me out with this??
Cheers,
Olly
If the status bar and keyboard are always in landscape then the problem should not be in shouldAuto... method. It might be in viewDidLoad. Also, try the following: in project-info.plist, set "Initial interface orientation" as landscape left/right, "clean" the project and run.

Resources