Fix scrollview-offset-calculation (#690)

This commit is contained in:
Nathan Mattes 2022-11-27 22:05:20 +01:00
parent fa696a6f36
commit 32bc94322d
2 changed files with 12 additions and 8 deletions

View File

@ -206,9 +206,8 @@ extension WelcomeIllustrationView {
} }
} }
func update(currentPage: WelcomeContentPage, contentOffset: CGFloat) { func update(contentOffset: CGFloat) {
// why does it jump back???
print("\(contentOffset)\(currentPage)")
//TODO: @zeitschlag update frames //TODO: @zeitschlag update frames
print(Int(contentOffset))
} }
} }

View File

@ -85,6 +85,7 @@ final class WelcomeViewController: UIViewController, NeedsDependency {
return pageController return pageController
}() }()
var currentPage: WelcomeContentPage = .whatIsMastodon var currentPage: WelcomeContentPage = .whatIsMastodon
var currentPageOffset = 0
} }
extension WelcomeViewController { extension WelcomeViewController {
@ -405,8 +406,11 @@ extension WelcomeViewController: UIPageViewControllerDelegate {
guard let currentViewController = pageViewController.viewControllers?.first as? WelcomeContentViewController else { return } guard let currentViewController = pageViewController.viewControllers?.first as? WelcomeContentViewController else { return }
currentPage = currentViewController.page currentPage = currentViewController.page
//FIXME: @zeitschlag fix
// welcomeIllustrationView.update(for: currentPage, contentOffset: 1000) if let pageIndex = WelcomeContentPage.allCases.firstIndex(of: currentPage) {
let offset = Int(pageIndex) * Int(pageViewController.view.frame.width)
currentPageOffset = offset
}
} }
} }
@ -455,8 +459,9 @@ extension WelcomeViewController: UIPageViewControllerDataSource {
extension WelcomeViewController: UIScrollViewDelegate { extension WelcomeViewController: UIScrollViewDelegate {
func scrollViewDidScroll(_ scrollView: UIScrollView) { func scrollViewDidScroll(_ scrollView: UIScrollView) {
print(scrollView.contentOffset.x) let weirdScrollViewJumpingCorrectionFactor = pageViewController.view.frame.width
//TODO: @zeitschlag sync view let contentOffset = CGFloat(currentPageOffset) + scrollView.contentOffset.x - weirdScrollViewJumpingCorrectionFactor
welcomeIllustrationView.update(currentPage: currentPage, contentOffset: scrollView.contentOffset.x)
welcomeIllustrationView.update(contentOffset: contentOffset)
} }
} }