From bdb1a120f1655a8ffc82565a5a9b44ff982db43c Mon Sep 17 00:00:00 2001 From: CMK Date: Thu, 27 May 2021 15:27:12 +0800 Subject: [PATCH] fix: profile avatar fade animation curve logic issue --- .../Profile/Header/ProfileHeaderViewController.swift | 10 +++++----- Mastodon/Scene/Profile/ProfileViewController.swift | 3 ++- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/Mastodon/Scene/Profile/Header/ProfileHeaderViewController.swift b/Mastodon/Scene/Profile/Header/ProfileHeaderViewController.swift index 87c25e4ad..0de6f47e3 100644 --- a/Mastodon/Scene/Profile/Header/ProfileHeaderViewController.swift +++ b/Mastodon/Scene/Profile/Header/ProfileHeaderViewController.swift @@ -362,7 +362,7 @@ extension ProfileHeaderViewController { } } - func updateHeaderScrollProgress(_ progress: CGFloat) { + func updateHeaderScrollProgress(_ progress: CGFloat, throttle: CGFloat) { // os_log(.info, log: .debug, "%{public}s[%{public}ld], %{public}s: progress: %.2f", ((#file as NSString).lastPathComponent), #line, #function, progress) updateHeaderBottomShadow(progress: progress) @@ -408,12 +408,12 @@ extension ProfileHeaderViewController { viewModel.isTitleViewContentOffsetSet.value = true } - // set avatar + // set avatar fade if progress > 0 { setProfileBannerFade(alpha: 0) - } else if progress > -0.3 { - // y = -(10/3)x - let alpha = -10.0 / 3.0 * progress + } else if progress > -abs(throttle) { + // y = -(1/0.8T)x + let alpha = -1 / abs(0.8 * throttle) * progress setProfileBannerFade(alpha: alpha) } else { setProfileBannerFade(alpha: 1) diff --git a/Mastodon/Scene/Profile/ProfileViewController.swift b/Mastodon/Scene/Profile/ProfileViewController.swift index 317d0234d..267e5bcee 100644 --- a/Mastodon/Scene/Profile/ProfileViewController.swift +++ b/Mastodon/Scene/Profile/ProfileViewController.swift @@ -652,7 +652,8 @@ extension ProfileViewController: UIScrollViewDelegate { // elastically banner image let headerScrollProgress = containerScrollView.contentOffset.y / topMaxContentOffsetY - profileHeaderViewController.updateHeaderScrollProgress(headerScrollProgress) + let throttle = ProfileHeaderViewController.headerMinHeight / topMaxContentOffsetY + profileHeaderViewController.updateHeaderScrollProgress(headerScrollProgress, throttle: throttle) } }