All Projects → toshi0383 → HorizontalStickyHeaderLayout

toshi0383 / HorizontalStickyHeaderLayout

Licence: MIT license
Horizontal UICollectionViewLayout with Sticky HeaderView

Programming Languages

swift
15916 projects
ruby
36898 projects - #4 most used programming language
objective c
16641 projects - #2 most used programming language

Projects that are alternatives of or similar to HorizontalStickyHeaderLayout

Centeredcollectionview
A lightweight UICollectionViewLayout that 'pages' and centers its cells 🎡 written in Swift
Stars: ✭ 965 (+1278.57%)
Mutual labels:  uicollectionview, tvos, carthage, uicollectionviewlayout
Admozaiccollectionviewlayout
ADMozaicCollectionViewLayout is yet another UICollectionViewLayout subclass that implements "brick", "mozaic" or Pinterest style layout.
Stars: ✭ 226 (+222.86%)
Mutual labels:  uicollectionview, carthage, uicollectionviewlayout
Blueprints
🌀 Blueprints - A framework that is meant to make your life easier when working with collection view flow layouts.
Stars: ✭ 874 (+1148.57%)
Mutual labels:  uicollectionview, tvos, uicollectionviewlayout
Columbus
A feature-rich country picker for iOS, tvOS and watchOS.
Stars: ✭ 23 (-67.14%)
Mutual labels:  tvos, carthage
Squaremosaiclayout
An extandable mosaic UICollectionViewLayout with a focus on extremely flexible customizations 🔶
Stars: ✭ 243 (+247.14%)
Mutual labels:  uicollectionview, uicollectionviewlayout
CPCollectionViewWheelLayoutSwift
New url:https://github.com/ParsifalC/CPCollectionViewKit Objective-C Version:https://github.com/ParsifalC/CPCollectionViewWheelLayout
Stars: ✭ 16 (-77.14%)
Mutual labels:  uicollectionview, uicollectionviewlayout
Lxreorderablecollectionviewflowlayout
Extends `UICollectionViewFlowLayout` to support reordering of cells. Similar to long press and pan on books in iBook.
Stars: ✭ 1,831 (+2515.71%)
Mutual labels:  uicollectionview, uicollectionviewlayout
Dots
Lightweight Concurrent Networking Framework
Stars: ✭ 35 (-50%)
Mutual labels:  tvos, carthage
CPCollectionViewWheelLayout
An interesting wheel layout of collection view.Swift version:https://github.com/ParsifalC/CPCollectionViewKit
Stars: ✭ 16 (-77.14%)
Mutual labels:  uicollectionview, uicollectionviewlayout
TVKit
UI components for tvOS
Stars: ✭ 20 (-71.43%)
Mutual labels:  tvos, carthage
PunycodeSwift
PunycodeSwift is a pure Swift library to allows you to encode and decode punycoded strings
Stars: ✭ 19 (-72.86%)
Mutual labels:  tvos, carthage
ExcelCollectionViewLayout
An Excel-like UICollectionView's layout.
Stars: ✭ 32 (-54.29%)
Mutual labels:  uicollectionview, uicollectionviewlayout
CollectionLayouts
A collection of UICollectionViewLayouts
Stars: ✭ 64 (-8.57%)
Mutual labels:  uicollectionview, uicollectionviewlayout
Chatlayout
ChatLayout is an alternative solution to MessageKit. It uses custom UICollectionViewLayout to provide you full control over the presentation as well as all the tools available in UICollectionView. It supports dynamic cells and supplementary view sizes.
Stars: ✭ 184 (+162.86%)
Mutual labels:  uicollectionview, uicollectionviewlayout
JQCollectionViewAlignLayout
A custom layout object based on flow layout. Added supports for horizontal, vertical alignment and RTL direction of collection view items.(available for both UICollectionView and NSCollectionView)
Stars: ✭ 69 (-1.43%)
Mutual labels:  uicollectionview, uicollectionviewlayout
Collectionviewslantedlayout
A CollectionView Layout displaying a slanted cells
Stars: ✭ 2,029 (+2798.57%)
Mutual labels:  uicollectionview, uicollectionviewlayout
CSStickyFlowLayoutHeaders
UICollectionView replacement for your amazing headers
Stars: ✭ 16 (-77.14%)
Mutual labels:  uicollectionview, uicollectionviewlayout
Mechanica
A cross-platform library of Swift utils to ease your iOS | macOS | watchOS | tvOS and Linux development.
Stars: ✭ 27 (-61.43%)
Mutual labels:  tvos, carthage
Closures
Swifty closures for UIKit and Foundation
Stars: ✭ 1,720 (+2357.14%)
Mutual labels:  uicollectionview, carthage
Cpcollectionviewkit
Interesting UICollectionView layouts and transitions
Stars: ✭ 140 (+100%)
Mutual labels:  uicollectionview, uicollectionviewlayout

HorizontalStickyHeaderLayout

Horizontal UICollectionViewLayout with Sticky HeaderView

platforms Carthage compatible Cocoapods pod License

Requirements

  • iOS9+
  • tvOS9+

How to use

Just implement these 5 required delegate methods.

extension ViewController: HorizontalStickyHeaderLayoutDelegate {
    private enum Const {
        static let headerSize = CGSize(width: 100, height: 38)
        static let itemSize0  = CGSize(width: 50, height: 50)
        static let itemSize1  = CGSize(width: 80, height: 80)
        static let headerLeft: CGFloat = 8
    }
    func collectionView(_ collectionView: UICollectionView, hshlSizeForItemAtIndexPath indexPath: IndexPath) -> CGSize {
        if indexPath.section % 2 == 0 {
            return Const.itemSize0
        } else {
            return Const.itemSize1
        }
    }
    func collectionView(_ collectionView: UICollectionView, hshlSizeForHeaderAtSection section: Int) -> CGSize {
        return Const.headerSize
    }
    func collectionView(_ collectionView: UICollectionView, hshlHeaderInsetsAtSection section: Int) -> UIEdgeInsets {
        return UIEdgeInsets(top: 0, left: Const.headerLeft, bottom: 20, right: 20)
    }
    func collectionView(_ collectionView: UICollectionView, hshlMinSpacingForCellsAtSection section: Int) -> CGFloat {
        return 20
    }
    func collectionView(_ collectionView: UICollectionView, hshlSectionInsetsAtSection section: Int) -> UIEdgeInsets {
        return UIEdgeInsets(top: 0, left: 0, bottom: 0, right: section == 4 ? 0 : 20)
    }
}

Optionally you can define contentInset for outer margin.

See Example for detail.

Animated header Y position for tvOS for free!

How to implement

  • On focus, call updatePoppingHeaderIndexPaths() to recalculate the popping header indexPaths to get the latest indexPaths.
  • Listen to pop indexPaths change on scroll by implementing collectionView(_:,hshlDidUpdatePoppingHeaderIndexPaths:) delegate method.
  • animate container view of your header view.

See Example for recommended implementation.

    // Either in UICollectionViewDelegate or this override method.
    override func didUpdateFocus(in context: UIFocusUpdateContext, with coordinator: UIFocusAnimationCoordinator) {
        layout.updatePoppingHeaderIndexPaths()
        let (pop, unpop) = self.getHeaders(poppingHeadersIndexPaths: self.layout.poppingHeaderIndexPaths)
        UIView.animate(withDuration: Const.unpopDuration, delay: 0, options: [.curveEaseOut], animations: {
            unpop.forEach { $0.unpopHeader() }
        }, completion: nil)
        coordinator.addCoordinatedAnimations({
            pop.forEach { $0.popHeader() }
        }, completion: nil)
        super.didUpdateFocus(in: context, with: coordinator)
    }

    func collectionView(_ collectionView: UICollectionView, hshlDidUpdatePoppingHeaderIndexPaths indexPaths: [IndexPath]) {
        let (pop, unpop) = self.getHeaders(poppingHeadersIndexPaths: self.layout.poppingHeaderIndexPaths)
        UIView.animate(withDuration: Const.unpopDuration, delay: 0, options: [.curveEaseOut], animations: {
            unpop.forEach { $0.unpopHeader() }
            pop.forEach { $0.popHeader() }
        }, completion: nil)
    }

Install

Carthage

github "toshi0383/HorizontalStickyHeaderLayout"

CocoaPods

pod "HorizontalStickyHeaderLayout"

Development

  • Xcode 12
  • Swift 5.3

License

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].