Using "View As" device other than active device results in layout issues - interface-builder

This one is best demonstrated with a video. The layout of my view changes based on which device I "View As: " in Interface Builder. It looks like changing this setting modifies the rects in Interface Builder, and then those changes stick. Is there a better way to prevent this from happening?
(It doesn't matter which device I use. If "View As" doesn't match the device, something will appear off.)

I figured this one out. It was a missing constraint. I was adding my view to a page view controller, but forgot to constraint the child view in the process:
marqueeViewController.addChildViewController(pageViewController)
marqueeViewController.containerView.addSubview(pageViewController.view)
// ** This constraint was missing, and is needed to resize the child view. **
Layout.edges(parent: marqueeViewController.containerView, child: pageViewController.view)
The rectangle of my views were changing size as I changed the "View As:" setting in Interface Builder. And since there was no constraint to reel them back in, they stayed set at the different size.

Related

IB Constraints dont show the same on device

I have a problem with Xcode IB constraints. To be frank, I never used it and now I inherited a project where I need to bring a fix.
IB shows things correctly, but at run time I get somethin different. I tried to play with some of the parameters in IB, but nothing helps.
So, my question is: How can I get on the device what I see in IB.
Here's IB:
On the device, the 'Fin de Course' is going into next field and Promo Code gets stuck.
What can I do?
I assumed that you already set the constraint correctly but your view is different when the app is running compared to Interface Builder or Storyboard. My suggestion is try to check the "orange" constraint. This is where the view gets "wrong" position on runtime.
The solution is to click the view which has "orange" constraint, then press Cmd + Opt + = in the keyboard. You will see the position will be updated.
But if you want to change the position of the view, you cannot just drag and drop if the constraints are still exist. The old constraint will still active. You have to update the constraint manually. You also can delete all constraints of the view first, then drag and drop the view into your desired location, and then set the new constraint.

NSToolbarItem and Auto Layout

I have a window with a programmatically created toolbar, which is populated with an NSToolbarItem that has a custom view defined in a xib file. If I check "Translate Masks into Contraints" for the view, then it doesn't resize itself correctly, so its content gets squashed even though I set its compression resistance priority to 750. If I uncheck that on the other hand, then I get a "Detected missing constraints" error at runtime. Also, the content of my view then resizes itself correctly, but it ends up clipped like so:
So it looks like the toolbar sticks my view into a container view and, in order to get the correct behaviour, I should set up layout constraints that allow my view to position itself correctly. However, I don't see how to access that container view... Any idea what I am doing wrong?
I am probably missing something obvious since one would think that this is a very standard setup, but Google didn't come up with anything.
Answering my own question, I opened a support request with Apple, the outcome of which is that this is now being treated as a bug by Apple.
In case anyone else runs into this, a good workaround is to create an intermediate view which contains the toolbar view as a subview with constraints #"H:|[toolbarView]" and #"V:|[toolbarView]", has translatesAutoresizingMaskIntoConstraints=YES and to use this view as the toolbar item. It then suffices to listen for size change notifications of toolbarView and to adjust the size of its superview accordingly.

"View As" option in Interface Builder stuck in one view

I have multiple view controllers for my app and I've been working on one view at a time in Interface Builder to make sure they work on all screen variations. I used "View As" option quite frequently to see how UI looks in different screen sizes. I just finished working on one view controller and want to move onto another view to do the same. However, the "View As" option does not change the screen size of the new view which I have currently selected. Instead, it changes the screen size of the view controller that I worked previously. This option seems stuck with the first view controller. Is that a bug or I'm doing wrong?
Just in case if anybody runs into the same problem, here what I was doing wrong. I need to set Simulation Size value of the viewcontroller that I want to work on to "Fixed" instead of "Freeform". Otherwise, it won't work.

Xcode 8 attribute "hidden" does not hide view in Interface Builder

seems like Apple change how Interface Builder behaves in Xcode 8? Because when I check hidden in Attributes Inspector on a view in Interface Builder, that view is still visible.
This makes it very tedious to work with views where some views needs to be the view with the highest "z value", the front most view that is.
Is there some other way to show the green view in this example, than to change the order of them to the right (i.e. change their "z value")
In the image below hidden is checked, but I still don't see the green view below. You can download this trivial project at github
When the project is run, the green view is indeed shown, but the issues is that it is annoying when working in Interface Builder.
Am I missing something?
I have the same opinion on it and I also believe that it's annoying. I with they gave you the choice to update the actual storyboard before runtime or not but they didn't so for now we have to deal with it.
There is a quick alternative option though. Hidden will not update in the storyboard but alpha will. If you change the alpha it will update in the storyboard so if you want to see the view behind it just change alpha to 0. You can always change it back easily or if your doing it in code, instead of unhiding your view just change the code so the alpha is set to 1.
How about unchecking the installed checkbox of the red view?
This has also the flaw that you have to remember to reinstall it, but you don't have to change the z-order of your views.
This is deliberate. We wouldn't want a view to be hidden from you, the editor, just because it will be hidden when the app runs. You can easily select a covered view, such as the green view, using Shift-Control-Click on the red view (or use the document outline at the left of your screen shot).

Warning: Scene is unreachable due to lack of entry point and does not have an identifier for runtime access.Swift

I did some searches about this warning. I am pretty sure I have all the storyboard ID in all view controllers and I did select an initial controller. But, the warning is still here. The only thing I am still wondering is do I also need to set the storyboard ID for navigation controller? If this is not a case, any suggestions? Thanks.
I think you did not select the initial ViewController. Go to your active storyboard, choose your initial ViewController then click on the attribute inspector on the top right corner of Xcode then click on the "In Initial View Controller" marker. For more check the image

Resources