Managing auto rotation in Storyboards - ios5

I'm working on an app that has several storyboard scenes.
I'd like to support any rotation of the device.
When I start, the first scene auto-rotataion works fine. The problem seems to be when I add more scenes and connect them via segues. Say, you click a menu button and segue to another scene... that next scene pops up in portrait mode and doesn't auto rotate...
Should I use a navigation controller to bring up the view and rotate it... Or am I not using the correct segue?

All you scenes may or may not need to have their own subclass (depending on inheritance). Assign the subclass to the respective scene.
You then need to set the supported rotation values in the subclass. eg.:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return YES;
}

Related

How do I enable orientation change for a specific Storyboard scene?

I have a systemic portrait-mode storyboard.
However I want to be able to rotate one scene to landscape mode without affecting other storyboard scenes.
Is this possible and how would I implement it?
Override the supportedInterfaceOrientations method in the view controller you want to allow landscape in, to return UIInterfaceOrientationMaskAllButUpsideDown or whichever value is suitable. This property is also configurable from the storyboard.
This will not affect the possible orientations of other view controllers; the app's UI orientation will automatically change back to portrait when you go to another scene.
You might need to uncheck Device Orientation options located in the project's General Settings for this to take effect (I didn't need to, but it seems to be necessary for some people):

Why doesn't my view display in Landscape instead of Portrait mode?

I use to define my UIViews programmatically, setting the orientation via code. I haven't touched Interface Builder in a while and I've decided to go for the new Storyboarding system.
I was pretty happy until I found out that although I have set, in the inspector pane, the appropriate view controller to "Landscape", it never displays in another mode than portrait.
I commented in and out the code in my custom view controller:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationLandscape);
}
Nothing changes.
My View Controller is itself "under" a Navigation Controller on the Storyboard, so I suspect interference, and it's only the second view in the flow, so the fact that the application itself is defined as portrait should not interfere.
I am looking for ideas to test for at this point, since the application is stripped to so little code I really can't begin to guess where to look?
What supported orientations have you specified in Info.plist? In order for a UINavigationController to support rotation, all of it's child view controllers must also support rotation to the same orientation.

UIViewController shouldAutorotateToInterfaceOrientation not working properly

Alright, I am not entirely sure if I will explain this sufficiently, but here it goes.
In my application I have multiple viewControllers, that are added and removed to display different views, so on and so forth. Some of these controllers, I want to allow to rotate while other I only want in say portrait mode.
However, when I go and change the shouldAutorotateToInterfaceOrientation to return YES for a desired orientation, or even just always return YES, nothing happens when I rotate the device in some of the views.
The first view that I add to the application will rotate properly and does what I want it to do, but any subsequent view that I add to the window, just does not want to rotate as desired.
I set my parentview (main UIWindow), to autoresizeSubViews, and still nothing.
Any suggestions?
I found my problem with this was simply how I was implementing my transitions and adding new views to the screen. Before I was just taking a viewcontroller viewcontroller, and adding it as a subview to the main view, so the only thing that could control the rotation was that main viewcontroller. I did not know about the [self.navigationcontroller pushviewcontroller] thing existed. So yeah, that is what I use now and it does exactly what I need it to do.
The view, you want to allow rotation, you need implement shouldAutorotateToInterfaceOrientation with return YES; for every view! That should work, however, if you don't want to allow landscape mode, then can return NO; for landscape mode. (Default mode is portrait).

Separate interface orientations per view

I am working on an iPhone app with a UINavigationController interface and there I want all views to ONLY allow default portrait rotation except for one. I know I can return 'NO' in the shouldAutoRotate method but basically when I am in the view that does allow rotation and go back to the previous view, the other views are then stuck in landscape as well. Any ideas?
you need to change status bar orientation when you go back to previous view.

iOS - Rotation with a Nav Controller

It's a small but annoying issue. I'm using a navigation controller and it will not rotate. I was using the code before without a navigation controller and it was rotating beautifully. It isn't even calling "-(BOOL)shouldAutororateToInterfaceOrientation..." now so I'm at a bit of a loss.
Thanks in advance.
Edit: And yes I have "-(BOOL)canBecomeFirstResponder" set.
Edit2: I have it calling "-(BOOL)shouldAutororateToInterfaceOrientation..." now when the App first runs and at this point the screen is rotated but then when it shows the Navcontroller sets it back to portrait mode...
There's a problem with UIWindow propagating these events to view controllers other than the root one. If you're adding this controller directly to a UIWindow and it isn't the first one you've added, then add it to the root view instead.
Otherwise, you'll probably need to take a look at implementing your own rotation transformations. I've got a UIViewController subclass which does the heavy lifting for you on github here.
Your controller need to have return YES in:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Overriden to allow any orientation.
return YES;
}
Also if you have an UITabBarController, each controllers need that method to return YES.