我正在以编程方式创建scrollView,但是由于某些原因,我可以看到scrollView的滚动条,但是subViews没有滚动。在下面添加了我的代码
//create a closure for scroll view
let vcScrollView: UIScrollView = {
let scrollView = UIScrollView()
scrollView.translatesAutoresizingMaskIntoConstraints = false
scrollView.backgroundColor = UIColor.dark_background
return scrollView
}()
//create closure for dark view
let darkView: UIView = {
let view = UIView()
view.backgroundColor = UIColor.black
view.translatesAutoresizingMaskIntoConstraints = false
return view
}()
//create a closure for offer label
let offerLabel: UILabel = {
let label = UILabel()
label.translatesAutoresizingMaskIntoConstraints = false
label.textColor = UIColor.white
return label
}()
override func viewDidLoad() {
super.viewDidLoad()
modalPresentationCapturesStatusBarAppearance = true
view.addSubview(vcScrollView)
setUpViews()
}
func setUpViews(){
//scrollView
vcScrollView.topAnchor.constraint(equalTo: view.topAnchor).isActive = true
vcScrollView.leadingAnchor.constraint(equalTo: view.leadingAnchor).isActive = true
vcScrollView.trailingAnchor.constraint(equalTo: view.trailingAnchor).isActive = true
vcScrollView.bottomAnchor.constraint(equalTo: view.bottomAnchor).isActive = true
vcScrollView.contentSize.height = 1500
//Dark view
vcScrollView.addSubview(darkView)
darkView.leadingAnchor.constraint(equalTo: view.leadingAnchor).isActive = true
darkView.topAnchor.constraint(equalTo: view.topAnchor).isActive = true
darkView.trailingAnchor.constraint(equalTo: view.trailingAnchor).isActive = true
darkView.heightAnchor.constraint(equalToConstant: 130).isActive = true
//Offer Label
darkView.addSubview(offerLabel)
offerLabel.text = selectedOffer
offerLabel.font = UIFont(name: String.defaultFontR, size: 29)
offerLabel.textAlignment = .center
offerLabel.topAnchor.constraint(equalTo: darkView.topAnchor, constant: 95).isActive = true
offerLabel.leadingAnchor.constraint(equalTo: darkView.leadingAnchor, constant: 20).isActive = true
offerLabel.trailingAnchor.constraint(equalTo: darkView.trailingAnchor, constant: -20).isActive = true
}
也已将滚动视图添加为该视图的子视图。预先感谢
答案 0 :(得分:0)
我认为您应该使用scrollview提供暗视图的约束。 当前,您正在从视图中提供约束。像这样-
darkView.leadingAnchor.constraint(equalTo: vcScrollView.leadingAnchor).isActive = true
darkView.topAnchor.constraint(equalTo: vcScollView.topAnchor).isActive = true
darkView.trailingAnchor.constraint(equalTo: vcScollView.trailingAnchor).isActive = true
darkView.heightAnchor.constraint(equalToConstant: 130).isActive = true
还提供了底部约束,以便scollview可以适当地调整内容大小。
答案 1 :(得分:0)
问题是您的滚动视图的孩子正在使用int n1[]=new int[n];
锚点。切换它们以使用for (i = 0; i < n; i++) {
//create a NEW array
int n1[]=new int[n];
//calculate n1, yada, yada, yada
//create a new node with the new array
nodes[i]=cluster1.new node(i+1,sum,n1);
}
锚点。另外,可以使用宽度约束代替尾随约束。这将允许它上下滚动。
ensureBufferingHasFinished(serviceProvider) {
return new Promise(function (resolve, reject) {
(function waitForBufferingComplete(){
if (!serviceProvider.getBufferingStatus()) {
alert("RESOLVED");
return resolve();
}
setTimeout(waitForBufferingComplete, 250);
})();
});
}
如果要在darkView下包含视图,则需要提供子视图的底部锚点。