After an upgrade to the latest Xcode 11.3.1, I stumbled upon a problem in the Interface Builder. Specifically, I opened an old XIB file to replace a now deprecated
UIWebView with a
WKWebView, added it and wanted to recreate the constraints of the old web view, most of which were relative to the superview, but failed. I tried Ctrl-dragging from the new web view to the parent view in the visual editor or to the View item in the left sidebar, but it was not selectable; the buttons at the bottom didn’t offer that option either. I’ve never had this problem in earlier Xcodes.
After a while, I came up with a workaround when I could make a leading space to the previous web view (or any other component), then go to the constraint’s properties and change the second item to “Superview” (later I found the same workaround here: https://stackoverflow.com/questions/58105491/cannot-equal-height-to-superview-in-xcode-11/59456827#59456827). However when I created most of the constraints this way, the IB complained about conflicting constraints, which I couldn’t understand. If that’s the best thing we have to do, then Xcode is getting worse.
Finally after some time, I discovered that the newly added web view has the autoresizing masks turned on by default. To fix that, select the view, open the Size inspector (
Cmd+Option+6), and change “Layout” option from “Translates mask into constraints” to “Automatic”:
Now, magic, I can create the constraints to the superview! Why could I create only a subset of all constraints before? Why isn’t there a warning about this case somewhere in the IB? Why isn’t AutoLayout the default now? Beats me.