1

I added a Storyboard launch file to upgrade a project from iOS 4 to iOS 9. The app runs in the Simulator but nothing I do will centre views for iPhone5 and iPhone 6 or scale them to fill the frame. Instead they look like bonsai versions of an iPhone 4 pinned in the top left of the screen.

When I try to add constraints to centre the views by following the procedure described here, the menu will not give me options to choose the view I need to constrain.

Instead I get this.

enter image description here

The bottom two - Horizontally in Container and Vertically in Container - are the only options I can check. But pulling down on the arrow to the right of the text box only gives some of the options needed to Add Constraints

What do I need to do to enable the view option ?

EDIT 1.

And furthermore, when I try to constrain width and height I get this

enter image description here

All six options are in grey and none of the text boxes change

EDIT 2.

And using the Size Inspector to look at the view I am trying to centre and fill, the view has no constraints as shown below.

It is really starting to look like there is no simple way to launch an old app where views have been created programmatically and have Storyboard Launch automatically layout views to suit different iPhone screen sizes.

Size Inspector

Community
  • 1
  • 1
Greg
  • 1,750
  • 2
  • 29
  • 56
  • you also need to give the width and height constraints for the view. – Teja Nandamuri Jun 27 '16 at 12:20
  • do one thing ,from your subview to your super view drag mouse by pressing ctrl , by that you can make your subview horizontally and vertically centre to your superview – Anjali Bhimani Jun 27 '16 at 12:23
  • @Teja Nandamuri, the width and height constraints have the same problem (see my edit) – Greg Jun 27 '16 at 12:31
  • @Anjali Bhimani, one thing I need to clarify. My original code used no storyboard or Xib file but was created programmatically, i.e. multiple view switched by a multiviewViewController with a multiviewViewController delegate. So I would assume the superview is the multiviewViewController. Or is it the view loaded by the ViewController that Xcode added when I created the Storyboard launch file ? – Greg Jun 27 '16 at 12:46
  • superview is the view in which you are adding subview like its parent view – Anjali Bhimani Jun 27 '16 at 13:00
  • @Anjali Bhimani, so I understand that to mean that the superview is the view created by the Storyboard file. I tried click dragging from that view to multiviewViewController but it made no difference. – Greg Jun 27 '16 at 13:21

3 Answers3

1

The "Horizontally in Container" and "Vertically in Container" checkboxes affect individual views. The are "binary operations". If you select more than one view, these checkboxes cause all the views to be centered in their container.

In contrast, the other checkboxes in this popup align groups of views.

If, for example, you select 4 views and click "leading edges" then it creates a set of constraints that line up the leading edges of all the selected views. (Under the covers it creates enough pairs of constraints to line up all the views by their leading edges.)

If you only have 1 view selected then only the bottom 2 checkboxes ("Horizontally in Container" and "Vertically in Container") are meaningful and the others are dimmed. As soon as you select more than one view the others should be enabled.

Duncan C
  • 128,072
  • 22
  • 173
  • 272
  • @ Duncan, what you're saying makes sense. "Horizontally in Container" and "Vertically in Container" were the only options the dialogue allowed me to check. That is the only reason I checked them. – Greg Jun 27 '16 at 13:21
  • Ok... So you need to delete those constraints if that's not what you want. If you want to align 2 or more views by their leading/trailing/top/bottom edges or centers, you need to select > 1 item in IB, then bring up that popup again. Does that answer your question? – Duncan C Jun 27 '16 at 13:31
  • I've unchecked those two constraints. How do I delete them ? Or do I need to do this in Interface Builder ? – Greg Jun 27 '16 at 13:40
  • You need to do some reading on Interface builder. If you select a view and then click on the "size inspector" icon at the top of the inspector column, the size inspector will list the constraints attached to that view. You can then select the constraint(s) and hit the delete key. – Duncan C Jun 27 '16 at 13:44
  • You can also see/select/delete the constraints in the IB (Interface Builder) "document outline". – Duncan C Jun 27 '16 at 13:48
  • I suspect I'll need to do a lot of reading on IB because the view I want to select was not originally created with IB (see my comments to Anjali about MultiviewViewController) and it may not even be possible to use autolayout. Size Inspector for the view in MultiviewViewController shows “This view has no constraints” whether I set Layout Margins to Default or Explicit. Whether or not I tick the check box “Preserve Superview Margins” width and height of the View are grey in SI (see my 2nd edit). And when I select Align, Pin or Resolve AutoLayout Issues, add constraints is greyed out. – Greg Jun 27 '16 at 21:26
  • I'm having the same issue after adding a UIView. IB seems impossible to use even after trying after a year or more, there's never ending problems with it. – Chewie The Chorkie Mar 21 '18 at 18:29
1

I had the same problem because on Show the Size inspector > Layout, "Autoresizing Mask" was selected, by changing the value for "inferred (Constrains)" it will resolve this problem illustration

0

Select the view you would like to constrain. Then tap the button to the right of the one you have selected and use that menu to define your autolayout constraints. If you want it to work for all devices make sure your storyboard is on the wAny hAny size class setting.

Max
  • 1,143
  • 7
  • 7
  • @ Max, but the dialogue won't allow me select the view I would like to constrain. Or do you mean I should select this some where else ? – Greg Jun 27 '16 at 13:35
  • You can select the object in the storyboard itself. – Max Jun 27 '16 at 15:30