簡體   English   中英

如何在視圖中居中滾動視圖

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

我在視圖控制器的視圖中添加了一個滾動視圖。 在 iPhone XR 上,滾動視圖子視圖顯示在左側,因為 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