简体   繁体   English

如何在视图中居中滚动视图

[英]how to center the scroll view inside the View

I have a scroll view added to the View Controller's View.我在视图控制器的视图中添加了一个滚动视图。 On iPhone XR, the scroll view subviews appear to the left because the scrollView does not expand its parent's view and is not centered.在 iPhone XR 上,滚动视图子视图显示在左侧,因为 scrollView 不会展开其父视图且未居中。 How can I make the scroll view take the full width and height of its parent's view and center it?如何使滚动视图采用其父视图的全宽和高度并将其居中?

add below constraint to scrollview将以下约束添加到滚动视图

 scrollview.translatesAutoresizingMaskIntoConstraints = false
    self.view.addSubview(scrollview)
    scrollview.topAnchor.constraint(equalTo: self.view.topAnchor, constant : 0).isActive = true
    scrollview.leadingAnchor.constraint(equalTo: self.view.leadingAnchor, constant : 0).isActive = true
    scrollview.trailingAnchor.constraint(equalTo: self.view.trailingAnchor, constant :0).isActive = true
    scrollview.centerXAnchor.constraint(equalTo: self.view.centerXAnchor, constant: 0).isActive = true
    scrollview.bottomAnchor.constraint(equalTo: self.view.bottomAnchor, constant: 0).isActive = true

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM