PeekPan combines 3D Touch and pan gestures to cycle through a collection of views while Peeking.
It's possible to have a gesture recognizer track the user's touch location while Peeking.
This just provides a way to travel through a range of indices with the mechanics figured out.
The main files used in this library are:
-
PeekPanGestureRecognizer.swift:
Begins tracking the user's touch location once the Peek preview is displayed and ends once the touch is released. -
PeekPanCoordinator.swift:
Correlates the user's touch location to a range of indices within an adjustable panning area. -
PeekPanViewController.swift:
AUIViewControllerused as an optional way to display differentUIViewon the Peek preview.
##Getting started via CocoaPods
sudo gem install cocoapods
Create a Podfile in your project directory:
pod init
Add the following to your Podfile project's target:
pod 'PeekPan'
Then run CocoaPods with pod install.
Finally, include PeekPanCoordinator.swift, PeekPanGestureRecognizer.swift, and (optional) PeekPanViewController.swift in your project.
Make sure to include a bridging header that imports <UIKit/UIGestureRecognizerSubclass.h> for PeekPanGestureRecognizer.swift to build correctly.
The component is targeted for use with iOS 9 but can support iOS 8 and greater.
##How to setup
-
Initialize
PeekPanCoordinatorwith a view controller's view to add a gesture recognizer and set the bounds of the panning area. -
Set the coordinator's data source and have a return value for
maximumIndex(for peekPanCoordinator: PeekPanCoordinator) -> Int. Also set the coordinator's delegate and its methods to receive updates. -
Call
setup()orsetup(at: index)inpreviewingContext(previewingContext:viewControllerForLocation:)to setup the coordinator at a particular index and retreive data from the data source. -
Call
end(true)inpreviewingContext(previewingContext:commitViewController:)to change the state of the coordinator and reset its values.
-
To use
PeekPanViewController, setup the coordinator using the directions above and set its delegate to the view controller. Also set the coordinator's data source to a class that follows its protocol. -
Return a view to
view(for peekPanViewController:atIndex:) -> UIViewwhen there's a change in index orview(for peekPanViewController:atPercentage:) -> UIViewwhen the user's touch location changes.PeekPanViewControllerDelegateis a subclass ofPeekPanCoordinatorDelegateso all of the coordinator's delegate methods are available to the view controller's delegate.
####Additional References
PeekPan uses some images from Behance made by the following authors licensed under CC BY 4.0:
- Toros Köse - toroskose : “Iceland 2015”
- Hakob Minasian - HakobDesigns : “Concept Art Portfolio”
- Vivien Bertin - vivienbertin : “Line-up #3”
- Alberto Seveso - indiffident : “Quinteassential”
