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.
Related
I have a UIViewController in iOS 9 that does not draw correctly when the view appears in landscape mode.
However if the view appears in portrait mode, and then is changed to landscape everything is fine.
This happens both on the simulator and devices. I am using Interface Builder to set the heights and constraints of the subviews. I do not do any resizing of frame sizes or updates to constraints in code.
So I tried to force a redraw similar to a change of orientation, but I could not get it to work and I am not sure if this is the best approach.
Does anyone have an idea how to solve this?
In your ViewControllers, you will need to override the shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) method to return YES when the app should rotate:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return interfaceOrientation == UIInterfaceOrientationPortrait || interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight;
}
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));
}
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;
}
I have created a project, with both portrait and landscape orientation. What should I do to keep only a few screens rotatable?
Play with:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}
If you have a UITabBarController, then you you will have problems, because either all rotate or none. Although I think there are some workarounds.
I want to make a landscape iPad app.
I did below 3 things. the simulator orientation is landscape which is correct. However, the content is 90 degrees wrong, but they are right in the storyboard view, landscape. Is there anything I need to check?
I set my storyboard as landscape.
May project I already set "supported interface orientations" = landscape
Also used this code in view controller:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
if (interfaceOrientation==UIInterfaceOrientationLandscapeLeft || interfaceOrientation==UIInterfaceOrientationLandscapeRight)
return YES;
else
return NO;
}
Make sure "Initial interface orientation" set in your Info.plist as well.
Supported Interface Orientations is one thing. It didn't work for me until I did the following:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft);
}
You have to use the following code on ALL of your viewcontrollers
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation==UIInterfaceOrientationLandscapeLeft || interfaceOrientation==UIInterfaceOrientationLandscapeRight)
}