gpt4 book ai didi

ios- ScrollView 中的所有页面未加载自定义uiview

转载 作者:行者123 更新时间:2023-11-28 12:09:09 26 4
gpt4 key购买 nike

自定义 uiview 仅在第一页加载,这是我正在处理的代码:

import UIKit

class MainViewController: UIViewController, UIScrollViewDelegate {

@IBOutlet weak var scrollView: UIScrollView!

var customframe: CGRect!

override func viewDidLoad() {
super.viewDidLoad()
customframe = CGRect(x: 0.0, y: 0.0, width: self.scrollView.frame.width, height: self.scrollView.frame.height)

scrollView.layer.masksToBounds = true
scrollView.layer.cornerRadius = scrollView.frame.height/4
}
override func viewWillAppear(_ animated: Bool) {
self.loadScrollView()
}
func loadScrollView() {
scrollView.backgroundColor = UIColor.black
scrollView.delegate = self
scrollView.isPagingEnabled = true
scrollView.contentSize = CGSize(width: scrollView.frame.size.width * 5, height: scrollView.frame.size.height)
scrollView.showsHorizontalScrollIndicator = true
for i in 0..<5 {
print(self.scrollView.frame.size.width)

let progressChartView = ProgressChartView(frame: customframe)//initialise cgdraw
progressChartView.setNeedsDisplay()
self.scrollView.addSubview(progressChartView)

}
}

这里的 progressChartView 是 UIView 子类的实例,我想在 scrollView 的所有 5 个页面中填充它,但它只在第一页加载。

如果我遗漏了什么,请帮忙。提前致谢。

最佳答案

您将多个 ProgressChartView 放在同一位置

替换你的代码

 for i in 0..<5 {
print(self.scrollView.frame.size.width)

let progressChartView = ProgressChartView(frame: customframe)//initialise cgdraw
progressChartView.setNeedsDisplay()
self.scrollView.addSubview(progressChartView)

}

for i in 0..<5 {
print(self.scrollView.frame.size.width)
let frame = CGRect(x: i * self.scrollView.frame.origin.x,y:0,width:self.scrollView.frame.size.width,height:self.scrollView.frame.size.height)
let progressChartView = ProgressChartView(frame: frame)//initialise cgdraw
progressChartView.setNeedsDisplay()
self.scrollView.addSubview(progressChartView)

}

关于ios- ScrollView 中的所有页面未加载自定义uiview,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48878191/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com