按比例约束UIView

时间:2018-04-07 23:09:35

标签: ios autolayout uikit uilayoutguide

我想以相对的方式定位我的观点。我想要使​​用百分比而不是像素。假设我想将按钮的中心定位在其超视距高度的25%处。我该怎么做?

一种方法是:

button.topAnchor.constraint( equalTo: superView.topAnchor, constant: /* compute constant "dynamically") .isActive = true

但这很愚蠢,因为我们在许多Layout Margin API函数中都有一个multiplier参数。

但是如果我输入button.centerYAnchor.constraint,则建议的所有完成都不会显示任何带有multiplier参数的函数,但名称中包含systemSpacing的函数除外。我已经研究过"系统间距"但无法弄清楚它的作用。

如果我有这个约束:

button.topAnchor.constraintEqualToSystemSpacingBelow(rootView.topAnchor, multiplier: 0.2).isActive = true

视图直接位于其superView的顶部。

1 个答案:

答案 0 :(得分:0)

我还没有找到一种方法来处理布局锚点,但是这是通过直接创建structure(list(Season = c(1516, 1516, 1516, 1516, 1516, 1516, 1516, 1516, 1516, 1516, 1516, 1516, 1516, 1516, 1516, 1516, 1516, 1516, 1516, 1516, 1516, 1516, 1516, 1516, 1516, 1516, 1516, 1516, 1516, 1516, 1516, 1516, 1516, 1516, 1516, 1516, 1516, 1516, 1516, 1516), Date = c("2015-06-29", "2015-06-29", "2015-06-29", "2015-06-29", "2015-06-29", "2015-06-29", "2015-06-29", "2015-06-29", "2015-06-29", "2015-06-29", "2015-06-29", "2015-06-29", "2015-06-29", "2015-06-29", "2015-06-29", "2015-06-29", "2015-06-29", "2015-07-01", "2015-07-01", "2015-07-01", "2015-07-01", "2015-07-01", "2015-07-01", "2015-07-01", "2015-07-01", "2015-07-01", "2015-07-01", "2015-07-01", "2015-07-01", "2015-07-01", "2015-07-01", "2015-07-01", "2015-07-01", "2015-07-01", "2015-07-02", "2015-07-02", "2015-07-02", "2015-07-02", "2015-07-03", "2015-07-03"), Player.Name = c("Annett Niall", "Baldwin Luke", "Barry Darren", "Bower Ryan", "Clegg Justin", "Heathcote Tom", "Howard Ben", "Humphreys Perry", "Kirwan Carl", "Kirwan Carl", "Kitchener Andrew", "Lewis Sam", "Lewis Sam", "Milasinovich Gareth", "Schonert Nick", "Stelling Max", "Taylor Huw", "Annett Niall", "Baldwin Luke", "Barry Darren", "Bower Ryan", "Clegg Justin", "Hammond Dean", "Heathcote Tom", "Howard Ben", "Humphreys Perry", "Kirwan Carl", "Kirwan Carl", "Lewis Sam", "Lewis Sam", "Milasinovich Gareth", "Schonert Nick", "Stelling Max", "Taylor Huw", "Bower Ryan", "Kitchener Andrew", "Milasinovich Gareth", "Taylor Huw", "Annett Niall", "Baldwin Luke"), OdometerTotal = c(1320, 1335, 1310, 1295, 1260, 1253, 1348, 1220, 1379, 1379, 1221, 1271, 1271, 1256, 1275, 1350, 1311, 1438, 1497, 1299, 1361, 1287, 3053, 1346, 1612, 1543, 1460, 1460, 1340, 1340, 1162, 1275, 1492, 1371, 4837, 4881, 5008, 5801, 1719, 1679), Chronic = c(NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_), Acute = c(NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_), Chronic_weighted = c(NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_), Acute_weighted = c(NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_), ACR = c(NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_), ACR_weighted = c(NA_real_, NA_real_, NA_real_, NA_real_, NA _real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_)), .Names = c("Season", "Date", "Player.Name", "OdometerTotal", "Chronic", "Acute", "Chronic_weighted", "Acute_weighted", "ACR", "ACR_weighted"), row.names = c(NA, -40L), class = c("grouped_df", "tbl_df", "tbl", "data.frame"), vars = "Player.Name", drop = TRUE, indices = list( c(0L, 17L, 38L), c(1L, 18L, 39L), c(2L, 19L), c(3L, 20L, 34L), c(4L, 21L), 22L, c(5L, 23L), c(6L, 24L), c(7L, 25L), c(8L, 9L, 26L, 27L), c(10L, 35L), c(11L, 12L, 28L, 29L), c(13L, 30L, 36L), c(14L, 31L), c(15L, 32L), c(16L, 33L, 37L )), group_sizes = c(3L, 3L, 2L, 3L, 2L, 1L, 2L, 2L, 2L, 4L, 2L, 4L, 3L, 2L, 2L, 3L), biggest_group_size = 4L, labels = structure(list( Player.Name = c("Annett Niall", "Baldwin Luke", "Barry Darren", "Bower Ryan", "Clegg Justin", "Hammond Dean", "Heathcote Tom", "Howard Ben", "Humphreys Perry", "Kirwan Carl", "Kitchener Andrew", "Lewis Sam", "Milasinovich Gareth", "Schonert Nick", "Stelling Max", "Taylor Huw")), row.names = c(NA, -16L), class = "data.frame", vars = "Player.Name", drop = TRUE, .Names = "Player.Name")) 来实现的:

NSLayoutConstraint