[英]Center Vertically UIStackView inside UIScrollView with scroll
您好,将UIStackView居中在具有滚动功能的ScrollView中是不可能的...
我尝试了很多事情,但是最好的事情是这样的:
stackView = new UIStackView
{
Axis = UILayoutConstraintAxis.Vertical,
Alignment = UIStackViewAlignment.Center,
};
scroll = new UIScrollView() { };
Add(scroll);
scroll.AddSubview(stackView);
scroll.EnableAutoLayout();
scroll.FullSizeOf(View);
stackView.AddArrangedSubview(logo);
stackView.AddArrangedSubview(_activityIndicatorView);
//... more items
logo.HeightAnchor.ConstraintEqualTo(72).Active = true;
enterpriseCodeField.HeightAnchor.ConstraintEqualTo(50).Active = true;
enterpriseCodeField.WidthAnchor.ConstraintEqualTo(0.65f * View.Frame.Size.Width).Active = true;
//... more items
stackView.SetCustomSpacing(35, logo);
stackView.SetCustomSpacing(35, _activityIndicatorView);
//... more items
View.AddConstraint(NSLayoutConstraint.Create(stackView, NSLayoutAttribute.CenterY, 0, scroll, NSLayoutAttribute.CenterY, 1, 0));
View.AddConstraint(NSLayoutConstraint.Create(stackView, NSLayoutAttribute.CenterX, 0, scroll, NSLayoutAttribute.CenterX, 1, 0));
此方法scroll.EnableAutoLayout(); 将:TranslatesAutoresizingMaskIntoConstraints = false;
此方法scroll.FullSizeOf(View); 要:设置领先的尾随等
有人可以帮我吗? 我做错了什么? 在android中,实现此行为非常容易...
非常感谢。
您可以使用scrollview centerX锚点约束。 这样,您可以将滚动视图的centerX锚点约束设置为与scrollView相同。
[更新的链接]我上传了一个项目,其中包含一些代码,可以实现您所需要的。 请在这里检查-> ScrollViewTest
该链接现在应该可以工作了
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.