我猜会有更多的人在寻找它,但它无处可寻。
我想要的是使一个或多个子视图的UIStackView浮动,一旦滚动视图中包含的UIStackView得到滚动通过的顶部(S)的视图。其行为应类似于表视图头。
发布于 2015-09-15 16:57:23
我会告诉你我的第一个想法。
尝试使用来自UIScrollViewDelegate的委托来检测滚动,如下所示
func scrollViewDidScroll(scrollView: UIScrollView) {
}检查滚动视图的当前Y,如下所示:
scrollView.contentOffset.y设置您的条件,如果为真,则更改UIStackView的位置。
但我不推荐这样的解决方案。也许检查UI最佳实践并坚持使用表视图的标题会更好
发布于 2016-12-21 04:27:57
@Rebel Designer,你听说过ScrollableStackView库吗?这是github的页面:
https://github.com/gurhub/ScrollableStackView
下面是一些示例代码:
Swift
import ScrollableStackView
var scrollable = ScrollableStackView(frame: view.frame)
view.addSubview(scrollable)
// add your views with
let rectangle = UIView(frame: CGRect(x: 0, y: 0, width: 100, height: 55))
rectangle.backgroundColor = UIColor.blue
scrollable.stackView.addArrangedSubview(rectangle)
// ...Objective-C
@import ScrollableStackView
ScrollableStackView *scrollable = [[ScrollableStackView alloc] initWithFrame:self.view.frame];
scrollable.stackView.distribution = UIStackViewDistributionFillProportionally;
scrollable.stackView.alignment = UIStackViewAlignmentCenter;
scrollable.stackView.axis = UILayoutConstraintAxisVertical;
[self.view addSubview:scrollable];
UIView *rectangle = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 55)];
[rectangle setBackgroundColor:[UIColor blueColor]];
// add your views with
[scrollable.stackView addArrangedSubview:rectangle];
// ...希望能有所帮助。
https://stackoverflow.com/questions/32426637
复制相似问题