Figure out a way to attach to scrolling in pages (#690)

This commit is contained in:
Nathan Mattes 2022-11-27 14:16:09 +01:00
parent c925e48385
commit fa696a6f36
2 changed files with 23 additions and 28 deletions

View File

@ -205,32 +205,10 @@ extension WelcomeIllustrationView {
}
}
}
func update(currentPage: WelcomeContentPage, contentOffset: CGFloat) {
// why does it jump back???
print("\(contentOffset)\(currentPage)")
//TODO: @zeitschlag update frames
}
}
#if canImport(SwiftUI) && DEBUG
import SwiftUI
struct WelcomeIllustrationView_Previews: PreviewProvider {
static var previews: some View {
Group {
UIViewPreview(width: 375) {
let view = WelcomeIllustrationView()
view.layout = .compact
return view
}
.previewLayout(.fixed(width: 375, height: 1500))
UIViewPreview(width: 547) {
let view = WelcomeIllustrationView()
view.layout = .regular
return view
}
.previewLayout(.fixed(width: 547, height: 1500))
}
}
}
#endif

View File

@ -145,6 +145,13 @@ extension WelcomeViewController {
view.addSubview(pageViewController.view)
pageViewController.didMove(toParent: self)
let scrollviews = pageViewController.view.subviews.filter { type(of: $0).isSubclass(of: UIScrollView.self) }.compactMap { $0 as? UIScrollView }
for scrollView in scrollviews {
scrollView.delegate = self
}
NSLayoutConstraint.activate([
pageViewController.view.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor),
pageViewController.view.leadingAnchor.constraint(equalTo: view.leadingAnchor),
@ -398,6 +405,8 @@ extension WelcomeViewController: UIPageViewControllerDelegate {
guard let currentViewController = pageViewController.viewControllers?.first as? WelcomeContentViewController else { return }
currentPage = currentViewController.page
//FIXME: @zeitschlag fix
// welcomeIllustrationView.update(for: currentPage, contentOffset: 1000)
}
}
@ -443,3 +452,11 @@ extension WelcomeViewController: UIPageViewControllerDataSource {
}
}
}
extension WelcomeViewController: UIScrollViewDelegate {
func scrollViewDidScroll(_ scrollView: UIScrollView) {
print(scrollView.contentOffset.x)
//TODO: @zeitschlag sync view
welcomeIllustrationView.update(currentPage: currentPage, contentOffset: scrollView.contentOffset.x)
}
}