【问题标题】:Implement UIScrollview swift 3实现 UIScrollview swift 3
【发布时间】:2018-02-07 03:46:37
【问题描述】:

我的项目结构是这样的: -看法 --UIScrollView - -看法 ----containerItems

我正在尝试让我的屏幕可滚动但始终是静态的,这是我的代码:

class LoginCtrl: UIViewController {
    let svPantalla: UIScrollView = {
        let sv = UIScrollView(frame: UIScreen.main.bounds)
        sv.backgroundColor = UIColor(r: 31, g: 90, b: 161)
        sv.contentSize = CGSize(width: 0, height: 0)
        sv.isScrollEnabled = true
        sv.contentOffset = CGPoint(x: 10, y: 20)
        sv.translatesAutoresizingMaskIntoConstraints = false
        return sv
    }()
    let v2: UIView = {
        let view = UIView()
        view.backgroundColor = UIColor.green
        view.translatesAutoresizingMaskIntoConstraints = false
        return view
    }()
    //contenedor textField
    let contenedorCampos: UIView = {
        let view = UIView()
        view.backgroundColor = UIColor(r: 255, g: 255, b: 255)
        view.translatesAutoresizingMaskIntoConstraints = false
        view.layer.cornerRadius = 5
        view.layer.masksToBounds = true
        return view
    }()
    let botonLoginRegistrarme: UIButton = {
        let button = UIButton(type: .system)
        button.backgroundColor = UIColor(r: 255, g: 152, b: 0)
        button.setTitle("Iniciar Sesion", for: .normal)
        button.setTitleColor(UIColor.white, for: .normal)
        button.titleLabel?.font = UIFont.boldSystemFont(ofSize: 16)
        button.translatesAutoresizingMaskIntoConstraints = false
        return button
    }()
    override func viewDidLoad() {
        super.viewDidLoad()
        view.addSubview(svPantalla)
        svPantalla.addSubview(v2)
        v2.addSubview(contenedorCampos)
        v2.addSubview(botonLoginRegistrarme)
        setear_posicion_svPantalla()
        setear_posicion_hijoV()
        setear_posicion_contenedor()
        setear_posicion_botonRegistrarme()
        //this functions are in the image added
    }
}

我的卷轴不工作,我该如何解决?

【问题讨论】:

  • 你真的能看到你的滚动视图吗?
  • 您必须在滚动子项中设置高度约束,然后滚动视图将计算其 contentSize 以使其可滚动。您也可以尝试手动设置但从未尝试过。在你的 viewDidLoad 中放 svPantalla.contentSize = CGSize(width: yourWidth, height: yourHeight)
  • 没有@JohnnyAW,但我可以看到背景色
  • @GIJOW 我把那个和我的 scrollView 出现但不滚动屏幕是静态的
  • 没有约束就很难实现

标签: ios iphone uiscrollview


【解决方案1】:

因为你已经设置了

sv.contentSize = CGSize(宽度: 0, 高度: 0)

请删除此行或添加值而不是 0。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-04-02
    • 2015-10-27
    • 1970-01-01
    • 2013-09-16
    • 1970-01-01
    • 2017-11-21
    • 2017-08-01
    • 2015-02-04
    相关资源
    最近更新 更多