这个表达式“父 View 边界的最小 x 值”在 Apple Documentation 中是什么意思?关于 UIScrollView
中的自动布局?
...some notes regarding Auto Layout support for UIScrollView:
In general, Auto Layout considers the top, left, bottom, and right edges of a view to be the visible edges. That is, if you pin a view to the left edge of its superview, you’re really pinning it to the minimum x-value of the superview’s bounds. Changing the bounds origin of the superview does not change the position of the view.
The UIScrollView class scrolls its content by changing the origin of its bounds. To make this work with Auto Layout, the top, left, bottom, and right edges within a scroll view now mean the edges of its content view.
1) 据我所知, View 的默认 bounds 是 (0, 0, width, height)。所以 x 是 0。
2) 一个 View 怎么可能有更多 x 值以使其最小化?
最佳答案
任何 View 的自动布局约束通常与 View 的可见边界有关,但是当涉及到 UIScrollView
时, Autolayout 约束与 scrollView 的 contentView
有关。
很明显,因为 scrollView
是……应该滚动的。
假设 scrollView
的 contentSize
是这样的:
myScrollView.frame = CGRectMake(0, 0, 100, 100);
myScrollView.contentSize = CGSizeMake(1000, 1000);
现在...
比如说,在这个 scrollView
中你有一个 subView
,类似于:
UILabel *lblTest = [UILabel alloc] initWithFrame:CGRectMake(0, 0, 50, 50)];
[lblTest setText:@"Where am I?"];
[myScrollView addSubView:lblTest];
滚动前:
myScrollView.contentOffset.y
将为0
myScrollView.bounds.y
将为0
myScrollView.frame.origin.y
将为0
lblTest.frame.origin.y
将为0
(并且将可见)
滚动后(到底部):
myScrollView.contentOffset.y
将更改为900
myScrollView.bounds.y
将也为900
myScrollView.frame.origin.y
将仍为0
lblTest.frame.origin.y
将为-900
(并且不再可见)
这是 Apple 文档的意思:
The UIScrollView class scrolls its content by changing the origin of its bounds.
现在……
如果 Autolayout 与 UIScrollView
的可见边界有关,那么无论您滚动多少,UILabel
都不会向上滚动。
但是……
由于 UIScrollView
中的自动布局与 ScrollView 的 contentSize
相关,因此自动布局约束在其中与滚动功能相关。
所以...
当您在 scrollView
中为 subViews
使用自动布局时,它将与 scrollView
的实际大小相关,而不是可见大小。
关于ios - 父 View 边界的最小 x 值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20298678/