Compare commits

..

No commits in common. "57c023c9731bee5f11e9ac31667e46fb7630d65e" and "59af29ff6413c88cb6282be464a94351d3f9c5a4" have entirely different histories.

2 changed files with 11 additions and 20 deletions

View File

@ -63,18 +63,11 @@ class ProfileHeaderCollectionViewCell: UICollectionViewCell {
} }
} }
override func preferredLayoutAttributesFitting(_ layoutAttributes: UICollectionViewLayoutAttributes) -> UICollectionViewLayoutAttributes { // overrides an internal method
switch state { // when the super impl is used, preferredLayoutAttributesFitting(_:) isn't called while the view is offscreen (i.e., window == nil)
case .unloaded: // and so the collection view imposes a height of 44pts which breaks the layout
return super.preferredLayoutAttributesFitting(layoutAttributes) @objc func _preferredLayoutAttributesFittingAttributes(_ attributes: UICollectionViewLayoutAttributes) -> UICollectionViewLayoutAttributes {
case .placeholder(let heightConstraint): return preferredLayoutAttributesFitting(attributes)
layoutAttributes.size.height = heightConstraint.constant
return layoutAttributes
case .view(let profileHeaderView):
let size = profileHeaderView.systemLayoutSizeFitting(layoutAttributes.size, withHorizontalFittingPriority: .required, verticalFittingPriority: .fittingSizeLevel)
layoutAttributes.size = size
return layoutAttributes
}
} }
enum State { enum State {

View File

@ -213,7 +213,7 @@ class ProfileViewController: UIViewController, StateRestorableViewController {
// old header cell must have the header view // old header cell must have the header view
let headerView = oldHeaderCell.addConstraint(height: oldHeaderCell.bounds.height)! let headerView = oldHeaderCell.addConstraint(height: oldHeaderCell.bounds.height)!
// Set the outgoing VC's header view mode to placeholder, so that it does not steal the header view back // Set the outgoing VC's header view mode to placeholder, so that it does steal the header view back
// in case it updates the cell in the background. // in case it updates the cell in the background.
old.headerViewMode = .placeholder(height: oldHeaderCell.bounds.height) old.headerViewMode = .placeholder(height: oldHeaderCell.bounds.height)
@ -224,13 +224,12 @@ class ProfileViewController: UIViewController, StateRestorableViewController {
} }
// disable user interaction during animation, to avoid any potential weird race conditions // disable user interaction during animation, to avoid any potential weird race conditions
view.isUserInteractionEnabled = false headerView.isUserInteractionEnabled = false
headerView.layer.zPosition = 100 headerView.layer.zPosition = 100
view.addSubview(headerView) view.addSubview(headerView)
let oldHeaderCellTop = oldHeaderCell.convert(CGPoint.zero, to: view).y let oldHeaderCellTop = oldHeaderCell.convert(CGPoint.zero, to: view).y
let headerTopOffset = oldHeaderCellTop - view.safeAreaInsets.top let headerTopOffset = oldHeaderCellTop - view.safeAreaInsets.top
let headerBottomOffset = oldHeaderCell.convert(CGPoint(x: 0, y: oldHeaderCell.bounds.maxY), to: view).y let headerBottomOffset = oldHeaderCell.convert(CGPoint(x: 0, y: oldHeaderCell.bounds.maxY), to: view).y// - view.safeAreaInsets.top
NSLayoutConstraint.activate([ NSLayoutConstraint.activate([
headerView.topAnchor.constraint(equalTo: view.topAnchor, constant: headerTopOffset), headerView.topAnchor.constraint(equalTo: view.topAnchor, constant: headerTopOffset),
headerView.bottomAnchor.constraint(equalTo: view.topAnchor, constant: headerBottomOffset), headerView.bottomAnchor.constraint(equalTo: view.topAnchor, constant: headerBottomOffset),
@ -273,17 +272,16 @@ class ProfileViewController: UIViewController, StateRestorableViewController {
} }
animator.addCompletion { _ in animator.addCompletion { _ in
old.removeViewAndController() old.removeViewAndController()
old.view.transform = .identity old.collectionView.transform = .identity
new.view.transform = .identity new.collectionView.transform = .identity
new.collectionView.contentOffset = origOldContentOffset new.collectionView.contentOffset = origOldContentOffset
// reenable scroll indicators after the switching animation is done // reenable scroll indicators after the switching animation is done
old.collectionView.showsVerticalScrollIndicator = true old.collectionView.showsVerticalScrollIndicator = true
new.collectionView.showsVerticalScrollIndicator = true new.collectionView.showsVerticalScrollIndicator = true
self.view.isUserInteractionEnabled = true headerView.isUserInteractionEnabled = true
headerView.transform = .identity headerView.transform = .identity
headerView.layer.zPosition = 0 headerView.layer.zPosition = 0
// move the header view into the new page controller's cell // move the header view into the new page controller's cell