滚动视图不水平滚动

时间:2019-03-18 12:03:59

标签: swift uiscrollview

我有一个自定义视图,我将其设置为父级:

func setup(){
    view.backgroundColor = .gray
    view.addSubview(chartView)
    chartView.leftAnchor.constraint(equalTo: view.leftAnchor).isActive = true
    chartView.rightAnchor.constraint(equalTo: view.rightAnchor).isActive = true
    chartView.topAnchor.constraint(equalTo: view.topAnchor, constant: statusAndNavigationBarHeight).isActive = true
    chartView.heightAnchor.constraint(equalToConstant: Dimensions.chartHeight.value).isActive = true
}

然后在该视图中,我试图设置一个滚动条:

scroll = UIScrollView.init(frame: CGRect(x: 0.0, y: 0.0, width: scrollWidth(), // print 728.0
                                                 height: Double(Dimensions.chartHeight.value))) // print 400.0
    scroll.isScrollEnabled = true
    scroll.showsHorizontalScrollIndicator = true
    addSubview(scroll)
}

仅此而已,当我启动应用程序时,我无法水平拖动和滚动,在调试编辑器中,我看不到它是宽幅滚动视图。

1 个答案:

答案 0 :(得分:3)

scrollView不会随着它的大小滚动,例如,它需要一个定义其内容大小的内容

let customLang = CustomLanguage() //declare at top

NSLocalizedString("StringToLocalize", tableName: nil, bundle: customLang.createBundlePath(), value: "", comment: “”) //use in each String

enter image description here