i made my view like this. just for a vertical scroll
enter picture description right here
view Elements: ScrollView, contentView(UIView), headerView, tableView
i positioned contentView on ScrollView , and headerView and TableView on ContentView.
Query: find out how to make scrollView’s dynamic peak.
really contentView’s peak will need to have dynamic peak proper?
class BusStopViewController: UIViewController {
let viewModel = ViewModel()
let disposeBag = DisposeBag()
non-public let headerView: BusStopInfoHeaderView = BusStopInfoHeaderView()
non-public var scrollView: UIScrollView = UIScrollView()
non-public let tableView: UITableView = {
let television = UITableView(body: .zero, fashion: .insetGrouped)
television.register(TableCell.self,
forCellReuseIdentifier: TableCell.identifier)
television.isScrollEnabled = false
return television
}()
let dataSource = RxTableViewSectionedReloadDataSource<DataSection> { dataSource, tableView, indexPath, merchandise in
guard let cell = tableView.dequeueReusableCell(withIdentifier: TableCell.identifier, for: indexPath) as? TableCell else { return UITableViewCell() }
cell.selectionStyle = .none
cell.bind(with: merchandise)
// tableView.body.dimension = tableView.contentSize
// print("tableView의 body.dimension.peak - (tableView.body.dimension.peak)")
return cell
} titleForHeaderInSection: { dataSource, indexPath in
return dataSource.sectionModels[indexPath].header
}
non-public let totalView = UIView()
override func viewDidLoad() {
tremendous.viewDidLoad()
view.backgroundColor = .yellow
scrollView.backgroundColor = .pink
configureUI()
tableView.rx.setDelegate(self)
.disposed(by: disposeBag)
bind()
tableView.rx.itemSelected
.subscribe { index in
print("(index) 선택됨")
}
.disposed(by: disposeBag)
}
func bind() {
Observable.simply(viewModel.sections)
.bind(to: tableView.rx.gadgets(dataSource: dataSource))
.disposed(by: disposeBag)
}
func configureUI() {
view.addSubview(scrollView)
// scrollView.updateContentSize()
print("(scrollView.contentSize.peak)")
[scrollView, totalView, headerView, tableView]
.forEach { elements in
elements.translatesAutoresizingMaskIntoConstraints = false
}
[headerView, tableView]
.forEach { elements in
totalView.addSubview(elements)
}
scrollView.addSubview(totalView)
NSLayoutConstraint.activate([
scrollView.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor),
scrollView.leadingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.leadingAnchor),
scrollView.trailingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.trailingAnchor),
scrollView.bottomAnchor.constraint(equalTo: view.safeAreaLayoutGuide.bottomAnchor),
totalView.widthAnchor.constraint(equalTo: scrollView.widthAnchor),
totalView.heightAnchor.constraint(greaterThanOrEqualToConstant: view.bounds.height),
totalView.topAnchor.constraint(equalTo: scrollView.contentLayoutGuide.topAnchor),
totalView.leadingAnchor.constraint(equalTo: scrollView.contentLayoutGuide.leadingAnchor),
totalView.trailingAnchor.constraint(equalTo: scrollView.contentLayoutGuide.trailingAnchor),
totalView.bottomAnchor.constraint(equalTo: scrollView.contentLayoutGuide.bottomAnchor),
headerView.topAnchor.constraint(equalTo: scrollView.topAnchor),
headerView.leadingAnchor.constraint(equalTo: scrollView.leadingAnchor),
headerView.trailingAnchor.constraint(equalTo: scrollView.trailingAnchor),
headerView.widthAnchor.constraint(equalTo: scrollView.widthAnchor),
tableView.topAnchor.constraint(equalTo: headerView.bottomAnchor),
tableView.leadingAnchor.constraint(equalTo: totalView.leadingAnchor),
tableView.widthAnchor.constraint(equalTo: totalView.widthAnchor),
tableView.heightAnchor.constraint(equalTo: totalView.heightAnchor),
])
}
}
extension BusStopViewController: UITableViewDelegate {
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return 55
}
}