6

I've used multipliers in my constraints, to size my views. However in my constraints for position I've used values, which I change for different sizing classes.

However using regular / regular sizing classes for iPad Pro it's positions values aren't big enough, but for other iPads it's fine.

I seriously don't have to add positioning views with multipliers to provide percentage spaces for all my views as well do I?

Jules
  • 7,190
  • 14
  • 93
  • 171

2 Answers2

2

Right, you don't have to use multipliers because Any value other than 1 creates a proportional constraint. For a Width attribute, for example, the width of the first item can be set to be twice the width of the second item

First thing I like to say that the resolution of ipad and ipad pro have abundant difference so in case of yours to add positioning views I just suggest you to use size class and use of priority, constant and relation (less than or equal, equal, greater than or equal) if necessary.

Hope, It'll helpful for you...

Akshar Darji
  • 377
  • 1
  • 11
  • Thanks, I hadn't realised that relations and priority would affect devices within the same sizing class. Although to be honest I haven't used and relations or priorities and really need to what some tutorials. – Jules Dec 03 '15 at 06:41
  • It's depends, but can you show me arrangement of views and what you want exactly for your mention devices? – Akshar Darji Dec 03 '15 at 06:55
  • I haven't got my Mac to hand atm, all I'm trying to do is create the same about of space at the top my screen for a sort of heading view. It's to close to the top on iPad pro and just right on other iPads. The left and right margins of the heading oddly seem ok. – Jules Dec 03 '15 at 06:58
  • did you trying without use of **Relative to margin** of leading/Trailing? – Akshar Darji Dec 03 '15 at 07:03
  • right but leading / trailing are taken relative margin it self. may be 20-20, you can check it ... – Akshar Darji Dec 03 '15 at 07:08
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/96854/discussion-between-akshar-darji-and-jules). – Akshar Darji Dec 03 '15 at 07:17
1

What we're after is to set the margin between the top of the screen and the top of the subview with relation to the size of the screen. This means the constraint must be related to the superview's height.

Trying to set the distance between the two views (In the traditional sense) is actually a bad idea in this case. Instead, try this.

Add a constraint to center your view vertically in the superview. Now, open up the constraint in the size inspector (The right toolbar).

If you set the multiplier to 0.01 (0 just puts it back in the center of the screen), your view will go past the top of the screen. Change the first item from Center Y to Top. Now your view will be at the top! enter image description here

From here, you can change the constant to move your view down a fixed amount and change the multiplier to move your view down further proportionally to the screen's height. The formula would look like

subViewYPosition = constant + (superviewHeight * multiplier)

You will need to adjust the constant and multiplier to suit your needs, but I believe this is a good solution to the problem. An example of this is shown below.

enter image description here

Sebastian Brosch
  • 37,059
  • 14
  • 61
  • 73
Hayden Holligan
  • 1,682
  • 2
  • 16
  • 24
  • Try making the constant smaller and the multiplier bigger, as I said, you'll have to tinker with those 2 values a little to find what you want. – Hayden Holligan Dec 10 '15 at 12:00
  • I don't understand why changing the constant from 0 to 1 puts the item at the top of the screen ? – Jules Dec 10 '15 at 13:52
  • Do you mean the constant or multiplier? The constant shouldn't do anything like that – Hayden Holligan Dec 10 '15 at 15:12
  • Let me know if you have any questions – Hayden Holligan Dec 10 '15 at 15:49
  • Here's an example of the changing constant from 0 to 10 and the top moving from center to top. https://www.evernote.com/l/AO94uWROMRxBwbNKwdaGw3KJoBo8sGWAgYEB/image.png – Jules Dec 11 '15 at 13:12
  • Also can I ask, how does the 'superview center Y' equate to the height? I guess this might be related to with a none 0 constant appears at the top, but I'm not sure why? I'm now trying to apply this to the spacing between two views, where constants don't seem provide the correct spacing, (however I can see that the superview height won't be involved, unless I do a spacing view) I can ask this as a separate question? – Jules Dec 11 '15 at 13:21
  • Here's my new question http://stackoverflow.com/questions/34225308/regular-regular-spacing-between-views-for-all-ipads-and-ipad-pro – Jules Dec 11 '15 at 14:01