实现迅速的UIScrollView 3
问题描述:
我的项目的结构是这样的: - 查看 --UIScrollView ---查看 ---- containerItems实现迅速的UIScrollView 3
我试图让我的屏幕滚动的,但始终是静态的,这是我的代码:
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
}
}
答
由于已设置
sv.contentSize = CGSize(宽度:0,高度:0)
请删除此行或添加值而不是0
+0
我加了但我有同样的错误 –
你能实际上看到你的滚动视图? – JohnnyAW
你必须在你的滚动子元素中为高度设置约束,那么滚动视图将计算它的contentSize以使其可滚动。您也可以尝试手动设置,但从未尝试过。在你的viewDidLoad中加入'svPantalla.contentSize = CGSize(width:yourWidth,height:yourHeight)' – GIJOW
no @JohnnyAW但是backgroundcolor我可以看到 –