0

I've read and put into practise a number of tutorials and watched a number of videos in relation to auto layout and sizing classes, however I have a few questions.

I'm a little confused about auto layout relations and how they work when applied to multipliers. Also why you need to reverse constraints.

I've found this tutorial which highlights where I'm confused.

enter image description here

Taken from http://www.raywenderlich.com/113768/adaptive-layout-tutorial-in-ios-9-getting-started

Jules
  • 7,190
  • 14
  • 93
  • 171

2 Answers2

1

The first item is the object that you actually want to apply the constraint to. The second item is the object you want the constraint to be related to. Assuming you linked up the constraints correctly you shouldn't have to reverse the items at all. The multiplier is exactly what a multiplier should do.

The relationship "Less than or equal" means that the cloud's height can be smaller than 400, but not larger. This is helpful when you're adding other constraints that might conflict with each other.

Example: if the superview's height is the first item and the cloud's height is the second item, and the multiplier is 1, the superview's height will be equal to the cloud's height. If you reverse the items, the cloud's height will be equal to the superview's height.

Now, let's say the cloud's height is item 1 and the superview's height is item 2. If the superview's height is 1000, the cloud's height will be 1000. If you change the multiplier to 0.4, the cloud's height will be the superview's height * 0.4, so 1000 * 0.4 = 400.

If we then set the relation from equal to less than or equal, it will probably stay the same. If we then add a constraint; setting the cloud's height to be 500, we will get a conflict. If we change the constraint from 500 to 300, your cloud's height will be 300.

Hope this helps!

Edit: this link and this link should help you grasp some of the constraint features.

Hayden Holligan
  • 1,682
  • 2
  • 16
  • 24
  • OK, thanks, when I'm looking at the iPad 2 and the iPad pro constant values don't look the same, I end up having to use multipliers to create a proportional height. However adding a different proportion constraints for each sizing class is rather tiresome. I'm just wondering how I can use a relation instead? Hope that make sense. – Jules Dec 09 '15 at 14:28
  • I'm assuming you're also developing for iPhone? All iPads have the same size class (Regular height and regular width, regardless of orientation). I don't know exactly what you're trying to do so it may be worth opening up a new question if you are unable to figure it out. – Hayden Holligan Dec 09 '15 at 14:45
  • Just noticed you already asked it! I think I know what you're looking for now, will answer soon – Hayden Holligan Dec 09 '15 at 15:05
0

Autolayout multiplier is simple.

In this example you got a cloud imageView inside a superview. Now you want this imageView height should change according to different screen.

0.4 means this : heightOfCloudImage = 0.4*heightOfSuperView.

If we reverse: That means

heightOfSuperView = 0.4*heightOfCloudImage (Does't make sense). Superview can't be smaller then parent.

So this is ratios between views.

Irfan
  • 4,750
  • 1
  • 27
  • 31