TGLStackedViewController
A stack layout with gesture-based reordering using UICollectionView -- inspired by Passbook and Reminders apps.
What's new in 2.2
- Reimplementation of item reordering using UIKit drag and drop on iOS 11.0
What's new in 2.0
- Uses iOS 9 collection view reordering API instead of own implementation, therefore minimum deployment target is iOS 9.0
- Unexposed items are pinned to bottom by default, now
- The exposed item can be collapsed interactively in addition to tapping it
- When pinning (the default) pan item down to switch back to stacked layout
- When just pushing cards aside use pinch gesture instead
- Improved sample project w/ lots of settings to tweak interactively
Getting Started
Take a look at sample project TGLStackedViewExample.xcodeproj
. You may use sample class TGLViewController
as a starting point for your own implementation.
Usage
Via CocoaPods:
- Add
pod 'TGLStackedViewController', '~> 2.2'
to your project'sPodfile
Via Carthage:
- Add
github "gleue/TGLStackedViewController", ~> 2.2
to your project'sCartfile
Or the "classic" way:
- Add files in folder
TGLStackedViewController
to your project
Then in your project:
- Create a subclass derived from
TGLStackedViewController
- Implement the
UICollectionViewDataSource
protocol in your subclass- Currently only 1 section is supported therefore your implementation of
-numberOfSectionsInCollectionView
has to return1
.TGLStackedViewController
provides a suitable implementation for you -- no need to overwrite. - Implement methods
-numberOfSectionsInCollectionView:
and-collectionView:cellForItemAtIndexPath
as usual. - New in 2.0:
TGLStackedViewController
's implementation of method-collectionView:canMoveItemAtIndexPath:
checks for stacked layout and a minimum number of 2 items before allowing reordering. Make sure to callsuper
in your implementation and honor it's result. - New in 2.0: Implement method
-collectionView:moveItemAtIndexPath:toIndexPath:
to update your data model after items have been reordered
- Currently only 1 section is supported therefore your implementation of
- Implement the
UICollectionViewDelegate
protocol in your subclassTGLStackedViewController
already implements methods-collectionView:shouldHighlightItemAtIndexPath:
,-collectionView:didDeselectItemAtIndexPath
, and-collectionView:didSelectItemAtIndexPath:
internally, so make sure to callsuper
in your implementation.- Method
-collectionView:targetContentOffsetForProposedContentOffset:
is crucuial for properly transitioning betwenn exposed and stacked layout, so make sure to callsuper
in your implementation.
- Place
UICollectionViewController
in your storyboard and set its class to your derived class- Make sure to set up the collection view's
delegate
anddataSource
connections properly
- Make sure to set up the collection view's
- New in 2.0:
TGLStackedViewController
does no longer create a layout object internally.- Set the collection view controller's layout class to
TGLStackedLayout
or your own subclass ofTGLStackedLayout
in the inspector in Interface Builder. - When creating a
TGLStackedViewController
in code you have to set the collection view's layout before presenting the view controller.
- Set the collection view controller's layout class to
Requirements
- ARC
- iOS >= 9.0
- Xcode 9.0
Credits
- Reordering in 1.x based on LXReorderableCollectionViewFlowLayout
- Original
Podspec
by Pierre Dulac - Carthage support by Hannes Oud
License
TGLStackedViewController is available under the MIT License (MIT)
Copyright (c) 2014-2019 Tim Gleue (http://gleue-interactive.com)
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.