iOS Storyboarding segue action changes orientation incorrectly - ios

Okay so I'm new to the whole storyboarding functionality in iOS 5. I have an application for iPad that is locked into landscape mode. Just to test out the seguing functionality, I took my initial view controller, added a button, dragged a new view controller next to it (which shows up in landscape mode visually on the designer), then tied the segue action to the button. I left everything defaulted.
Hitting the button on the initial view controller initiates the segue with no problems, and the new screen loads up, but ALWAYS in portrait mode.
What am I doing wrong? Is there some toggle I'm missing? I figured that if via the summary of the project, I have it locked into landscape left and right, it would assume I always want that orientation unless otherwise noted? Please help!

I had the same problem and managed it by adding a new own ViewControllerClass to the new scene.
Within the following auto created method, you can restrict the orientation to landscape only. This is also helpful for the Main Scene ViewController:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (UIInterfaceOrientationIsLandscape(interfaceOrientation));
}
Cheers,
Daniel

I have an application for iPad that is locked into landscape mode.
How are you locking it app-wide? Just want to make sure you are doing it correctly.
To lock an orientation in Storyboard mode, select your ViewController and on the Attributes inspector change the Orientation from Inferred to whatever you want it to be locked to.

What have you put in the orientation delegate method?
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft);
}

In the properties file for your app (YOURAPPNAME-Info.plist), located in the "supporting files" group, there is an array called "Supported interface orientations". Remove both landscape values from the array and your app will be locked in portrait orientation.

Related

ViewController and SubView are not rotating correctly

I am working on a landscape view for a currently existing application. I believe I have autoRotate, supported interface, etc set up correctly, I am actually reusing code that works with a much simpler app. However when the simulator is rotated into landscape mode, the correct view loads, but the status bar and view stay with the short edge of the iPad. I've attached a screenshot and code. Is the problem with a view controller higher up in the chain, or the appdelegate? I've traced the called controllers in the debugger and it appears they are dismissed once this page is loaded. I am fairly new-ish to obj-c so it is possible this is something simple I am missing, but I have checked all attributes for the .xib file and everything looks copasetic.
Some of the code:
-(BOOL)shouldAutorotate
{
return NO;
}
-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskAll;// | UIInterfaceOrientationMaskPortraitUpsideDown;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Overriden to allow any orientation.
return NO;
}![enter image description here][2]
-(void)orientationChanged{
UIInterfaceOrientation interfaceOrientation = [[UIDevice currentDevice] orientation];
if ((interfaceOrientation==UIInterfaceOrientationPortrait)||(interfaceOrientation ==UIInterfaceOrientationPortraitUpsideDown)){
self.view = self.portraitView;
} else {
self.view = self.landscapeView;
}
}
EDITS - This problem occurs on both iOS 7.1 and 6.1 and this is the first time any screen in the app supports a landscape view. To clarify the views, the portrait and landscape views are separate Views in single .xib file. The file owner class is set to the correct view controller class, and the parent view controller, a sales screen, should not rotate. It does not have a landscape view, but even with its autoRotate methods set to return YES the subview does not orient correctly.
Like 0x7ffffffff already said you need to allow rotation in your shouldAutorotate functions. Also you need to set up the supported rotation directions in your project setup.
First go to your project's settings:
Next you need to select all the orientations you want to support:
Another that is very important: ONLY the root View Controller will receive rotation events. If you nest a View Controller inside a View Controller then that nested Controller will not receive those events unless you wire them up manually from the parent. That's why I usually don't nest ViewControllers but use ad-hoc NSObjects or UIView implementations for nested views.
Last but not least: make sure your device is not rotation-locked: http://www.iphonefaq.org/archives/972915
The problem was occurring because a subclass of the customerView was not receiving the rotation notification. After tracking that class down it was a matter of setting up the NSNotificationCenter for orientation changes and then allowing autoRotation and supprotedInterfaceOrientations.

iOS >> Device Orientation >> Screen is Not Supporting Upside Down

I have a screen that supports Device Orientation.
Everything is working fine except for the fact that when I rotate the device upside down (home button at top), the rotation doesn't work (it's stuck on the last landscape settings).
I know of several places needed be updated to support this:
In the VC itself, I added the methods:
In the Project Target, I updated as follow:
In the Storyboard VC Scene, I updated as follow:
What am I missing here?
You also have to allow rotating to all orientations in every parent view controller of the current main view controller. For example, if your view controller is in navigation controller, try subclassing it and override the same methods as in your example.
Edit: As #JordanC mentioned, since iOS 7 you can implement UINavigationControllerDelegate method to return custom supported orientations:
- (UIInterfaceOrientationMask)navigationControllerSupportedInterfaceOrientations:(UINavigationController *)navigationController
As #eGanges mentioned the key point could be to subclass your UITabBarController (and override supportedInterfaceOrientations) if that is your initial view controller, in that case this is the only controller you should subclass (and of course you should add all the supported interface orientations to your app Info.plist file UISupportedInterfaceOrientations key)
Have you tested on real device?
anyway try this:
- (NSUInteger)supportedInterfaceOrientations {
return (UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskPortraitUpsideDown);
}

ios simulator orientation wrong on second

I have created a small app with just three views. I have only selected LandscapeRight orientation. in the iOS simulator only the first view shows up in landscape. The other views are in portrait. I can rotate the simulator, but the storyboard layout rotates with it and does not display correct.
the info.plist file has only the (Landscapre Right) orientation item.
Kind regards
Teddy
Like what Wilhelmsen had said, It is annoying but you must add the following code
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation{
return (toInterfaceOrientation == UIInterfaceOrientationLandscapeRight);
}
However, I would also like to add that you MUST ADD THIS INTO EACH SEPARATE VIEW CONTROLLER in order for it to rotate for the other view as well.
For instance, lets say I have viewcontroller_1 and viewcontroller_2, I have to go into both .m files of the controller and add the following code. If you dont, it may not rotate for one of the views.
Yes, this is annoying, but add this to your .m file and it works
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation{
return (toInterfaceOrientation == UIInterfaceOrientationLandscapeRight);
}

iOS change screen orientation on demand

I have an app with an UITableView at the home screen. I made this view to always be in landscape orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return UIInterfaceOrientationIsLandscape(interfaceOrientation);
}
If the user picks a row he will be taken to a UIPageViewController view. This second view can rotate to landscape and portrait. The problem is when I am in portrait mode on the UIPageViewController and I press the go back button, the first view which is supposed to be always in landscape mode now is in portrait. After I rotate it, it gets into landscape and stays there.
I was wondering maybe if there is a way to make my home screen go automatically into landscape when I go back to it.
Try the following
Create the view of your main screen in app in interface builder in Landscape mode.
Create uiview oultlet in interface class and connect it to above view.
IBOutlet UIVIew *myView;
Then in the viewDidLoad method set this
self.view = self.myView;
If you want to make a screen in a particular orientation then you can create a CustomNavigation controller and then present it in your app. You have to only return supportedInterfaceOrientations in this. If you want more detail and sample code click here.
Call shouldAutorotateToInterfaceOrientation manually when you go back. You can not force a "real" orientation change, that's a OS thing.
As said in the view controller programming guide, you can have a alternate landscape interface and before coming to home screen from any other view, you can check the orientation and push the corresponding interface onto the screen
Read this SO question and answer for better understanding of launching an app in landscape.Also go through above apple programming guide which i pointed to.
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. Hope this helped!
Use this, change the UIInterfaceOrientationLandscapeLeft to required orientation type as UIDeviceOrientationPortrait, UIDeviceOrientationLandscapeLeft etc.
NSNumber *value = [NSNumber numberWithInt:UIInterfaceOrientationLandscapeLeft];
[[UIDevice currentDevice] setValue:value forKey:#"orientation"];

Orientation problem when I set a RootViewController

I'm doing an universal ios game and I'm having an orientation problem. My app is all in landscape mode. If I do presentModelViewController is all ok, but if I do setRootViewController, the new controller appear in portrait mode.
What am I doing wrong?
I'm unsure if this was your problem, but I have an application that starts with one view controller in portrait mode and then I'm trying to present a second view controller in landscape mode. I'm using the setRootViewController technique as well so that I do not have to deallocate/reallocate the second view controller and lose my state information since users will be switching between the two views frequently.
I had the same issue where the second view controller would always be displayed in portrait mode instead of landscape, even though the view controller itself specifies that it never allows portrait mode.
The fix for me was to make sure that in the application delegate I presented the first view controller using
[window setRootViewController:controller];
instead of
[window addSubview:controller.view];
This was an older application, and the original template used addSubview by default. it seems that if there was not an original root view controller specified, the necessary orientation messages will never make it to subsequent view controllers that are set as root. Hope that helps!
Have you set the
UIInterfaceOrientation
key in your info.plist file to your desired orientation? (in this case landscape)

Resources