fix: profile title view not align center issue. resolve #117.

This commit is contained in:
CMK 2021-04-29 17:13:13 +08:00
parent 4b96ac4481
commit df2a73d96c
3 changed files with 12 additions and 3 deletions

View File

@ -328,7 +328,9 @@ extension ProfileHeaderViewController {
let nameTextFieldInWindow = profileHeaderView.nameTextField.superview!.convert(profileHeaderView.nameTextField.frame, to: nil) let nameTextFieldInWindow = profileHeaderView.nameTextField.superview!.convert(profileHeaderView.nameTextField.frame, to: nil)
let nameTextFieldTopToNavigationBarBottomOffset = containerSafeAreaInset.top - nameTextFieldInWindow.origin.y let nameTextFieldTopToNavigationBarBottomOffset = containerSafeAreaInset.top - nameTextFieldInWindow.origin.y
let titleViewContentOffset: CGFloat = titleView.frame.height - nameTextFieldTopToNavigationBarBottomOffset let titleViewContentOffset: CGFloat = titleView.frame.height - nameTextFieldTopToNavigationBarBottomOffset
titleView.containerView.transform = CGAffineTransform(translationX: 0, y: max(0, titleViewContentOffset)) let transformY = max(0, titleViewContentOffset)
titleView.containerView.transform = CGAffineTransform(translationX: 0, y: transformY)
viewModel.isTitleViewDisplaying.value = transformY < titleView.containerView.frame.height
if viewModel.viewDidAppear.value { if viewModel.viewDidAppear.value {
viewModel.isTitleViewContentOffsetSet.value = true viewModel.isTitleViewContentOffsetSet.value = true
@ -347,6 +349,7 @@ extension ProfileHeaderViewController {
} }
private func setProfileBannerFade(alpha: CGFloat) { private func setProfileBannerFade(alpha: CGFloat) {
profileHeaderView.avatarImageViewBackgroundView.alpha = alpha
profileHeaderView.avatarImageView.alpha = alpha profileHeaderView.avatarImageView.alpha = alpha
profileHeaderView.editAvatarBackgroundView.alpha = alpha profileHeaderView.editAvatarBackgroundView.alpha = alpha
profileHeaderView.nameTextFieldBackgroundView.alpha = alpha profileHeaderView.nameTextFieldBackgroundView.alpha = alpha

View File

@ -24,6 +24,7 @@ final class ProfileHeaderViewModel {
// output // output
let displayProfileInfo = ProfileInfo() let displayProfileInfo = ProfileInfo()
let editProfileInfo = ProfileInfo() let editProfileInfo = ProfileInfo()
let isTitleViewDisplaying = CurrentValueSubject<Bool, Never>(false)
init(context: AppContext) { init(context: AppContext) {
self.context = context self.context = context

View File

@ -172,13 +172,14 @@ extension ProfileViewController {
} }
.store(in: &disposeBag) .store(in: &disposeBag)
Publishers.CombineLatest3 ( Publishers.CombineLatest4 (
viewModel.suspended.eraseToAnyPublisher(), viewModel.suspended.eraseToAnyPublisher(),
profileHeaderViewController.viewModel.isTitleViewDisplaying.eraseToAnyPublisher(),
editingAndUpdatingPublisher.eraseToAnyPublisher(), editingAndUpdatingPublisher.eraseToAnyPublisher(),
barButtonItemHiddenPublisher.eraseToAnyPublisher() barButtonItemHiddenPublisher.eraseToAnyPublisher()
) )
.receive(on: DispatchQueue.main) .receive(on: DispatchQueue.main)
.sink { [weak self] suspended, tuple1, tuple2 in .sink { [weak self] suspended, isTitleViewDisplaying, tuple1, tuple2 in
guard let self = self else { return } guard let self = self else { return }
let (isEditing, _) = tuple1 let (isEditing, _) = tuple1
let (isMeBarButtonItemsHidden, isReplyBarButtonItemHidden, isMoreMenuBarButtonItemHidden) = tuple2 let (isMeBarButtonItemsHidden, isReplyBarButtonItemHidden, isMoreMenuBarButtonItemHidden) = tuple2
@ -197,6 +198,10 @@ extension ProfileViewController {
return return
} }
guard !isTitleViewDisplaying else {
return
}
guard isMeBarButtonItemsHidden else { guard isMeBarButtonItemsHidden else {
items.append(self.settingBarButtonItem) items.append(self.settingBarButtonItem)
items.append(self.shareBarButtonItem) items.append(self.shareBarButtonItem)