Skip to content

Commit 50deb76

Browse files
committed
Correctly invalidating layout allows correct frame after size changes (like rotation)
1 parent abb8bd6 commit 50deb76

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

ReplaceAnimation/ViewController.swift

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,9 +150,15 @@ class ViewController: UICollectionViewController {
150150
}
151151

152152
override func viewWillTransitionToSize(size: CGSize, withTransitionCoordinator coordinator: UIViewControllerTransitionCoordinator) {
153-
coordinator.animateAlongsideTransition({ (context) -> Void in
154-
self.collectionView?.collectionViewLayout.invalidateLayout()
153+
if let layout: StickyHeaderLayout = self.collectionView?.collectionViewLayout as? StickyHeaderLayout {
154+
layout.parallaxHeaderMinimumReferenceSize = CGSizeMake(size.width, 60)
155+
layout.parallaxHeaderReferenceSize = CGSizeMake(size.width, 0.56 * size.width)
156+
layout.itemSize = CGSizeMake(size.width, layout.itemSize.height)
157+
158+
coordinator.animateAlongsideTransition({ (context) -> Void in
159+
layout.invalidateLayout()
155160
}, completion: nil)
161+
}
156162
}
157163

158164
func handlePan(pan : UIPanGestureRecognizer) {

0 commit comments

Comments
 (0)