Nested Scroll Views
At first, the session presents how to make nested scroll views working together by using a UICollectionView in UIScrollView, while each UICollectionViewCell has a UIScrollView as the subview.
Meanwhile, the UICollectionView is the subclass of UIScrollView.
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
determine delta beyond catch point
adjust parent contentOffset by delta
translate child by delta
}Key points in this part:
When subview scroll, using a delegate call to scroll parent scrollview(set contentOffset).
When subview scroll, avoiding double scroll by transforming itself, transform itself back when scroll ends.
When
scrollViewWillEndDragging, adjust the scrollviewcontentOffset, change ratio between sub-scrollview and parent-scrollview.
Scrolling with UIKit Dynamics
In the second part, the session presents how to add special animation effect in the UICollectionView by customizing UICollectionFlowLayout by adding UIDynamicBehavior to UICollectionViewLayoutAttributes.
Subclass
UICollectionViewFlowLayoutCreate
UIDynamicAnimatorCreate
UIAttachmentBehaviorfor each itemStretch the attachments when scrolling
- (BOOL)shouldInvalidateLayoutForBoundsChange:(CGRect)newBounds {
CGFloat delta = newBounds.origin.y - self.collectionView.bounds.origin.y
shift layout attribute positions by delta
notify UIDynamicAnimator
}Memory Efficient Code
In the second part, when prepareLayout is called, all the behaviors of every cells will be created, initialized and attached to the cell. In this part, the behaviors will be added to the cell when the cell appear on the screen, and removed when the cell disappear from the screen, very efficient.
