"Freeform" size in IB - Storyboard - ios

As I understand and tried, if I change the simulated size of the ViewController in the storyboard it will still stretch its main "view" property to the whole screen.
So my question is when and why should I change this "Freeform" property?
Whenever I needed to make some overlay, I just make the main "view" transparent and create another view on top of that with my content, then I present it I do it as a container.
As I see there is no need for it, And I couldn't find anywhere in Apple documentation about it.

This property is only for simulating a different size.
ViewControllers do not always have to be fullscreen containers, for example View Controller containment, or the new iOS 7 View Controller transitions may lead to a View Controller that's size covers some partial area of the screen.
You would use the 'freeform' mode to change the size in interface builder, so you can simulate what the end size would be, whilst you work with it.

This was answered in the Q UIViewController Freeform size issue: uncheck "Resize View From NIB" in your View Controller's Attributes Inspector and your freeform view controller's view will indeed be decoded at the size you designed in your storyboard.

You are not quite on the right track. If you use Freeform for the size of the view controller, you can specify the desired size of your controller.
Also it's really important how you use the controller, how you set the springs & struts or layout constraints. If you set the springs or constraints to stretch your controller's view to "match" the parent size then the view will be stretched, if not it will keep the size you mentioned but not in all cases. For example if you present the view controller modally and you specify a different explicit size in IB then the view will have this size.
Usually you use the freeform property when you add the view controller as a child to another view controller programatically and you really want to have that fixed size.
If you push the view controller or you present it as modal view controller (and you use the modal presentation styles) then there is no need to use freeform.
Also another use of the freeform property is to preview the actual size of your view controller when is presented as a modal view controller using existent presentation styles.
Another wrongly implementation that I seen before regarding the size of the view controller's view is to check the size in viewDidLoad. Always check the size in viewWillAppear|| viewDidAppear.

Related

Embedding a UIViewController with dynamic height inside parent view controller

I am displaying a UIViewController(In NotificationContentExtension) with a child view controller. The parent controller is just adding to its view the view of child controller as subview.
The subview is all built with autolayout and constraints, which renders fine when not embedded in a view controller.
Currently, the parent notification is displayed as big as the parent view controller's view is configured to be in the extension's Info.plist file.
If I provide a height to the childcontroller's view in the parent view it renders as big as the parent but in case I don't initialise its frame, it doesn't render the child controller's view elements.
What I am seeking is to open the controller as big as the child view container's dynamic height make it to be.
To clarify, I believe what you're trying to achieve is a Modal "popup" View Controller than is smaller (in some way) than the View Controller that calls it, similar to the functionality of an Alert View Controller...
Go to your Storyboard and click on the child view controller with the custom height, then open the right pane to view the Size Inspector. I'm assuming here your Simulated Size = "Freeform" with your height and width. This will allow you to actually resize the View Controller in the Storyboard but the view controller will show up fullscreen.
Now click on the Attributes Inspector and in the 4th grouping down, check the box for Content Size "Use Preferred Explicit Size" and type in your simulated size. This will allow your Modal view controller to show up at the exact size you're asking.
To do this programmatically, try this in the calling ViewController's prepare for segue implementation:
destinationVC.preferredContentSize = CGSize(width: 300.0, height: 400.0)
Cheers :)

What is the difference between "Inferred" and "Freeform" in Xcode Storyboard?

I have a custom view which needs to be displayed on all the iPhone devices(4, 4S, 5, 5S, 6 and 6 Plus). When creating the custom view XIB, I have mentioned it as "Inferred" but it is not resizing for iPhone 6 and iPhone 6 Plus devices. I am not able to figure out the issue. I am confused on what would be actual differences between "Inferred" and "Freeform". Can someone please explain the differences?
Inferred resizes the scene according to its parent scene. For example if you have a scene that is the size of an iPad and then you add a new scene to your storyboard and create a segue to it, it will automatically resize to the same size as the iPad scene (where the segue originates from).
Freeform ignores the above rule and you're able to size it as you see fit, in the utility pane on the right.
Both of these however have nothing to do with how the view is displayed and sized on actual devices. For that you need to use auto layout and constraints. Or springs and struts. Some even do it in code if they need more flexibility.
“Inferred” is the default setting for storyboards and it means the scene will show a navigation bar when it’s inside of a navigation controller, a tab bar when it’s inside of a tab bar controller, and so on. You could override these settings if you wanted to, but keep in mind they are here only to help you design your screens. The Simulated Metrics aren’t used during runtime, they’re just a visual design aid that shows what your screen will end up looking like.
"FreeForm" Usually you use the freeform property when you add the view controller as a child to another view controller programmatically and you really want to have that fixed size.If you push the view controller or you present it as modal view controller (and you use the modal presentation styles) then there is no need to use freeform.Also another use of the freeform property is to preview the actual size of your view controller when is presented as a modal view controller using existent presentation styles.

"Present as Popover" segues and view size

Can anyone point to any guidance/documentation on how items should be placed in a view controller that will be displayed as a popover so that the components are appropriately positioned with auto layout?
Specifically: I'm working in Xcode 8.3 with the new "Present as Popover" segue, with the new "universal" storyboards. I add a view controller and then a popover segue to that view controller. When it is displayed, I see that roughly the top-left quadrant of the view controller is displayed as a popover, but that no auto layout appears to be taking place as far as I can see to accommodate the slightly different sizes of an iPad popover vs "full screen" behaviour on the different sized iPhones -- so in effect, a slightly different section of the view controller is visible depending on the device.
I assume this isn't really how things are supposed to work, and the whole raison d'être of the universal popover segue is to appropriately fit things to the popover size via auto layout? So can anyone shed some light on what I'm doing wrong or how popups are supposed to work with respect to auto layout?
Something to watch for with popovers is that on devices like the iPad, the size class for the popover is not the same as the controller which raises it.
You will probably find that the size class goes from regular width to compact width when you use a popover on an iPad. If you have layout coded to regular width for your popover content, then it will not work in the popover.
The size of the popover itself comes from the content size properties for the controller presented. You can set this size explicitly in the attribute inspector for the view controller or in code. See: How to present popover properly in iOS 8
To make the elements display correctly on screen, change the size class control to Any-Any (near the layout toolbar at the bottom of the Interface Builder canvas) before adding elements in the Storyboard in the View Controller that will act as a popover.

How to show an explicit size for a popover in storyboard

I have multiple popovers in my app and need each one of them to be exact sizes. When I set each view controller an explicit size, the explicit size doesn't show in storyboard, but it does in the simulator.
Select the view controller in the storyboard and set its Size pop-up menu in the Simulated Metrics section of its Attributes inspector to Freeform. Now you can adjust the size to match the size it will be when the app runs.
Do note, however, that the size of a view controller's view in the storyboard is completely unimportant. It has no effect on the app when it runs. The view controller's view is always resized to fit its surroundings when the app runs. The only thing that matters in this case the popoverContentSize or preferredContentSize - the storyboard is just a place to draw in. You should be using constraints in such a way that the fact that the view is resized when the app runs doesn't matter to you.

Size of Navigation Controller inside Popover on Storyboard canvas in Interface Builder

Note: this question is not about the size of views in the running app. It is strictly about the size of the Navigation Controller representation on the canvas in Interface Builder.
This image illustrates the problem behavior in Interface Builder.
I have not found a way to make the Navigation Controller representation smaller. As you can imagine, an iPad app with lots of Navigation Controllers in lots of Popovers causes the Storyboard canvas to get very crowded.
Note that in order to correct the size of the Navigation Controller's root view controller, I had to adjust the root view controller's Simulated Metrics Size to "Freeform", and then manually specify it's root view size to match the Container View size.
This illustration shows the desired behavior of the Navigation Controller element.
This illustration also gives a hint as to the cause of the problem. The size of the Container View does not trickle down to the Navigation Controller element if there is an interposing view controller.
I have found 3 similar questions, but none of them provide illustrations, and none directly address that this problem is still present in Xcode 5.
Resize NavigationController in InterfaceBuilder
How to resize UINavigationController in a storyboard editor
Popover size with UINavigationController in Storyboard
I have found no answers on the Apple Developer Forums from the past 90 days.
So the question is, is there some control or setting in Interface Builder that I am overlooking that will solve my problem?
One of the answers to the question listed above provides a trick which involves adding an unused View Controller and Container View for every Navigation Controller, but that is unsatisfactory because adding cruft to the Storyboard is worse than having oversized Navigation Controllers.
Not sure if this answers your specific situation, but after much searching I discovered that (at least in Xcode 5.1) there's a "View Controller" panel in the storyboard sidebar with a "Simulated Size" entry - pick "Freeform" and set your width and height as you wish.
I found a half-fix that makes this problem a bit more palatable: You can set the simulated metrics of the navigation controller to be Master (which is 320 points wide, portrait or landscape height) or Form Sheet (which is 540 x 620).
Then in the root view controller it contains, you can set the size you want (as you did) by making it freeform.
It looks like the size of this view is used for the popover by default (or you can set it explicitly on this view controller via the "Popover: Use Explicit Size" setting). Note, though, that if you are showing the navigation bar in the simulated metrics of this view controller, you have to compensate by subtracting the bar's height from the popover explicit size of the view or hiding it in the simulated metrics of the popover root view controller.

Resources