代码之家  ›  专栏  ›  技术社区  ›  Cody Potter

UIScrollView作为辅助视图的问题

  •  0
  • Cody Potter  · 技术社区  · 8 年前

    UIScrollView 作为辅助视图。我有一个名为 newDogView 并在代码中设置其约束。

    newDogView

    以下是相关代码:

    override func viewWillLayoutSubviews() {
        newDogView.translatesAutoresizingMaskIntoConstraints = false
        newDogScrollView.translatesAutoresizingMaskIntoConstraints = false
        newDogScrollView.heightAnchor.constraint(equalToConstant: 320.0).isActive = true
        newDogScrollView.widthAnchor.constraint(equalToConstant: 960.0).isActive = true
        newDogScrollView.contentSize = CGSize(width: 320, height: 320)
        newDogView.heightAnchor.constraint(equalToConstant: 320.0).isActive = true
        newDogView.widthAnchor.constraint(equalToConstant: 320.0).isActive = true
        newDogView.centerXAnchor.constraint(equalTo: view.centerXAnchor).isActive = true
        newDogView.centerYAnchor.constraint(equalTo: view.centerYAnchor).isActive = true
    }
    

    我不确定是否应该设置newDogView的高度和宽度。

    以下是我当前的视图层次结构和警告:

    Here is my view hierarchy and warning.

    这是我当前的故事板:

    Here is my storyboard.

    Content View Scroll View .

    iphone photo

    1 回复  |  直到 8 年前
        1
  •  0
  •   3stud1ant3    8 年前

    尝试更改内容大小

    CGSize(width: 320, height: 320)
    

    CGSize(width: 960, height: 320)
    

    newDogView.widthAnchor.constraint(equalToConstant: 960.0).isActive = true
    

    newDogView.widthAnchor.constraint(equalToConstant: 320.0).isActive = true