0
我的項目的結構是這樣的: - 查看 --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
}
}
你能實際上看到你的滾動視圖? – JohnnyAW
你必須在你的滾動子元素中爲高度設置約束,那麼滾動視圖將計算它的contentSize以使其可滾動。您也可以嘗試手動設置,但從未嘗試過。在你的viewDidLoad中加入'svPantalla.contentSize = CGSize(width:yourWidth,height:yourHeight)' – GIJOW
no @JohnnyAW但是backgroundcolor我可以看到 –