【发布时间】:2013-10-09 20:33:12
【问题描述】:
在this technical Note Apple 声明您可以通过向 UISCrollView 的超级视图添加约束来使 UIScrollView 的子视图固定/浮动。我试过了,但我做错了,我不知道是什么问题。
请注意,您可以通过在视图和滚动视图的子树之外的视图(例如滚动视图的超级视图)之间创建约束,使滚动视图的子视图看起来浮动(不滚动)在其他滚动内容之上。
这就是我所做的。我已经设置了 UIScrollView 并尝试将固定视图添加到滚动视图的顶部,如下所示:
_testOverlay = [[UIView alloc] init];
_testOverlay.backgroundColor = [UIColor blueColor];
_testOverlay.translatesAutoresizingMaskIntoConstraints = NO;
[self.scrollView addSubview:_testOverlay];
[self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"|[_testOverlay]|" options:0 metrics:nil views:NSDictionaryOfVariableBindings(_testOverlay)]];
[self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|[_testOverlay(64)]-(>=0)-|" options:0 metrics:nil views:NSDictionaryOfVariableBindings(_testOverlay)]];
但是,这不起作用,添加的视图将与滚动视图一起移动并且不会“浮动”。有什么想法吗?
【问题讨论】:
标签: ios uiscrollview header autolayout