Allow rotation only for one controller - ios

I need to lock all controllers from auto rotation except one. It must rotates both portrait and landscape. I have read this topic and tried this solutions
let value = UIInterfaceOrientation.LandscapeLeft.rawValue
UIDevice.currentDevice().setValue(value, forKey: "orientation")
but I had no luck, it didnt work. Maybe this is because I use navigation controllers, I saw some mentions of them in previous link but I didnt understand approach because author allowed orientation modes in Xcode preferences and then duplicated them in code.
Maybe some one can help with advice ?

The current method to handle rotation is viewControllerWillTransitionToSize:withTransitionCoordinator:. Documentation is at this link: https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIContentContainer_Ref/index.html#//apple_ref/occ/intfm/UIContentContainer/viewWillTransitionToSize:withTransitionCoordinator:
It's a little bit different because you're working with screen sizes not orientations. This is the new way of dealing with sizes and transitions. Think of it like a responsive layout instead of distinct rotation values. To put it a different way, you're not designing for "landscape orientation" anymore, but for a screen thats wider than it is tall. It's a subtle but important difference.
You could implement this method in different ways for different view controllers. If you're using a navigation controller and want to affect child views differently, first I'd say thats terrible UX most likely. But if you still want to do it, you could handle rotation in your Nav Controller.
You should not set the device orientation like that.

you can try this method. Paste this method on the view controller to make the device support portrait and landscape except upside down orientation.
func supportedInterfaceOrientations() -> UIInterfaceOrientationMask {
return UIInterfaceOrientationMaskAllButUpsideDown
}
But as chris suggested, you should use viewControllerWillTransitionToSize and handle everything regarding the orientations there.

Related

Obtaining safeAreaInsets for interface orientations?

I am using safeAreaInsets to respect iPhone X's notch and reserved menu areas.
This works great for when loading the view since the view is in the current interface orientation.
However, I need to know what the future values will be to handle animation in my willRotate method. UIViewController has a viewSafeAreaInsetsDidChange method, but that isn't updated until after the device has rotated. I need something like viewSafeAreaInsetsWillChange, but of course does not exist.
So, it seems that the only way to handle the animations in my willRotate method is by hard coding the safe area values, which is certainly far from ideal.
Is there anyway to obtain safe areas for a given orientation (portrait or landscape)?

iOS 7 status bar overlaps with view - did they have to make it like this?

I know this has been asked before, but none of these solutions work, and that's the reason of my posting. Please do not close before considering my case.
My plist already has UIViewControllerBasedStatusBarAppearance = false.
I have already tried applying deltas, but to no result.
Changing the top level view frame in ViewWillAppear (like self.view.frame) did not succeed.
I thought of increasing the view height (storyboard attribute inspector), in combination with deltas, but my top level view X, Y are disabled in storyboard attribute inspector.
My main view doesn't have any children views because I load them into main view either dynamically or load them from XIBs which are again shared by more than view controllers. These XIBs provide layout for both Portrait and Landscape. I don't know what approach is ideal for this kind of configuration, but I would like it better if solution lies along these lines.
This approach worked partially, but gave me inconsistent results.
What makes the solution tricky is the fact that I have to support all 4 orientations - this is something I handle in code via didRotate and willRotate delegates for my other views, but failing to do it for statusbar.
Please help...
Could this link be of any help?
You might have to use the new setEdgesForExtendedLayout: method to get this working consistently?
Also, have a look at these official docs if you haven't already done so.
I ended up writing my own function to shift my all subviews (remember, not top level views whose frame is fixated by IB).
It didn't spoil my work but imagine if this was the case for a very big project with so many screens, the limitations would have made it a nightmare.

Using Xcode Storyboards for rich rotating UI's

I am working on an iPad app that relies on a rather complex layout that seems to be beyond the abilities to the auto-resizing masks to rotate cleanly from portrait to landscape.
I can easily enough hand-tweak a layout in Interface Builder for each orientation, but I am puzzling over the most elegant and maintainable way to handle making the transition between the two different layouts.
Is there any way that this can be done with segues?
Is there a way I can easily snapshot two different layouts and use code to morph between them?
Am I better off trying to use HTML5 to do the page layout and not UILabels?
Are there other better techniques that I haven't even thought of yet?
Help is much appreciated - it seems like this shouldn't be so hard.
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;
}
EDIT:
I suggest loading a respective NIB by overriding willRotateToInterfaceOrientation:duration: and didRotateFromInterfaceOrientation:.

How to handle orientation change in iPad in an effective way?

I am developing an application in ipad and i need to make it in a way that it support the landscape and portrait orientations. I think we need to override some methods of UIViewController class and perfrom the orientation ,view resize, view positioning etc. Can anyone help me by providing your valuable suggessions in this?
Thanks,
Ajith
Have you read the 'Handling View Rotations' section of the UIViewController's class reference?
If you have, can you give a more specific situation you're having trouble with?

Changing iPad orientation, rotating statusbar, toolbars, but not the main view

I’m trying to set up an iPad test application, window-based, where I have a single view controller and a single view. When I rotate the iPad, I want the orientation of the toolbar to change, but not that of the view itself. For example, a sort of background view that you work in is fixed to the device, but the status bar and toolbars rotate around it. This would enable the user to work the view from all angles, but always with a correctly-oriented toolset.
A beautiful implementation of what I want can be found in the Brushes for iPad app, where the painting’s orientation is locked to the device, and the toolbars rotate around it. I think other painting apps do the same thing.
I’ve been trying to figure out how to do this, but after exhausting many many other questions here concerning orientation, I’m still at a loss.
Could anyone point me in the right direction towards a neat solution? A particular combination of autoresizes for the autoresizeMask? Countering the rotation animation with another one in the opposite direction? Using multiple concurrent view controllers, one for the rotating views and one for the non-rotating ones?
I’d very much appreciate it,
(Edit: Attempted to clarify the question, after Olie’s comment.)
To prevent rotation, you'd put this in your view controller's .m:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
But you say you still want the view frame to resize in response to the rotation. I haven't had a need to do this myself, so I'm not sure if it's sufficient to just set the autoresizingMask to have flexible width and height; you may also have to implement didRotateFromInterfaceOrientation: and use setNeedsLayout and/or resize the view manually.
I had a bug that did this a while back -- I'm pretty sure that what you're asking will get you a HIG-violation rejection from Apple. However, I'll give a shot at remembering what the problem was. I'm pretty sure it was something like this:
I had a tabbarViewController that said "I orient to any orientation."
One of the tabs was a regular-old UIViewController that said "I only do LandscapeLeft & L-Right"
When you rotated, the inside (UIVC) stayed put, but the outside (TabVC) rotated around things.
I might have some of the details backwards or otherwise convoluted, but the general ideas is: stacked VCs, not all one VC.
Good luck!
To the extent I have worked with I cannot see any simple answer to your question. What about rotating everything (tabbar, nav and status bar, your view controller) and then redrawing the content of your view controller in "old coordinates" so for the user it will look like it's not rotated?

Resources