https://github.com/rightpoint/shift
A library of custom iOS View Controller Animations and Interactions written in Swift.
https://github.com/rightpoint/shift
Last synced: about 1 year ago
JSON representation
A library of custom iOS View Controller Animations and Interactions written in Swift.
- Host: GitHub
- URL: https://github.com/rightpoint/shift
- Owner: Rightpoint
- License: other
- Created: 2015-12-10T15:56:45.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2016-01-14T18:11:41.000Z (over 10 years ago)
- Last Synced: 2025-03-22T11:43:20.530Z (over 1 year ago)
- Language: Swift
- Size: 425 KB
- Stars: 22
- Watchers: 8
- Forks: 0
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Shift
[](https://github.com/Carthage/Carthage)
[](https://github.com/CocoaPods/CocoaPods)
A library of custom iOS View Controller Animations and Interactions written in Swift.
## Installation with Carthage
Carthage is a decentralized dependency manager that automates the process of adding frameworks to your Cocoa application.
You can install Carthage with Homebrew using the following commands:
```sh
brew update
brew install carthage
```
To integrate Shift into your Xcode project using Carthage, specify it in your Cartfile:
`github "raizlabs/shift"`
## Installation with CocoaPods
CocoaPods is a dependency manager for Swift and Objective-C Cocoa projects.
To integrate Shift into your Xcode project using CocoaPods, specify it in your `Podfile`:
```ruby
pod 'Shift'
```
## Usage
First, make sure you import the Shift module: `import Shift`.
The rest is easy. If you are pushing a view controller to the navigation stack, follow these three steps:
- Set your navigation controller's delegate :
```swift
navigationController?.delegate = self
```
- Store the transition on your view controller:
```swift
var currentTransition: UIViewControllerAnimatedTransitioning?
```
- Extend your view controller to implement `UINavigationControllerDelegateTransitioning`. In your implementation, make sure to set the `currentTransition`:
```swift
extension ViewController: UINavigationControllerDelegate {
func navigationController(navigationController: UINavigationController,
animationControllerForOperation operation: UINavigationControllerOperation,
fromViewController fromVC: UIViewController,
toViewController toVC: UIViewController) -> UIViewControllerAnimatedTransitioning? {
if (operation == .Push && fromVC == self) {
/*
* set currentTransition here
*/
}
else if (operation == .Pop && toVC == self) {
}
return currentTransition
}
}
```
### SplitTransition (Push/Pop)
`SplitTransition` exposes 5 key properties:
1. `screenshotScope` - (optional, defaults to `.View`) - determines whether top and bottom views are sourced from container view or entire window
2. `splitLocation` (optional, defaults to `0.0`) - y coordinate where the top and bottom views part
3. `transitionDuration` (optional, defaults to `1.0`) - duration (in seconds) of the transition animation
4. `transitionDelay` (optional, defaults to `0.0`) - delay (in seconds) before the start of the transition animation
5. `transitionType` (optional, defaults to `.Push`) - `.Push`, `.Pop`, or `.Interactive`. Setting `transitionType` to `.Interactive` will allow users to control the progress of the transition with a drag gesture.
Set these properties in your implementation of `UINavigationControllerDelegateTransitioning`:
```swift
func navigationController(navigationController: UINavigationController,
animationControllerForOperation operation: UINavigationControllerOperation,
fromViewController fromVC: UIViewController,
toViewController toVC: UIViewController) -> UIViewControllerAnimatedTransitioning? {
if (operation == .Push && fromVC == self) {
let splitTransition = SplitTransitionController()
splitTransition.transitionDuration = 2.0
splitTransition.transitionType = .Push
splitTransition.splitLocation = currentCell != nil ? CGRectGetMidY(currentCell!.frame) : CGRectGetMidY(view.frame)
currentTransition = splitTransition
}
else if (operation == .Pop && toVC == self) {
currentTransition?.transitionType = .Pop
}
return currentTransition
}
```
### SplitTransition (Present/Dismiss)
Using `SplitTransition` to present a view controller modally is simple. For the presented view controller, set `modalPresentationStyle` to `.Custom`. For the `SplitTransition`, set `transitionType` to `.Presentation`, passing a presenting view controller and a presented view controller into the constructor. In addition, set your presented view controller's `transitioningDelegate` to the newly created `SplitTransition`.
```swift
// Configure destination view controller
let destinationViewController = UIViewController()
destinationViewController.modalPresentationStyle = .Custom
// Configure transition
let currentTransition = SplitTransition()
currentTransition?.transitionType = .Presentation(self, destinationViewController)
// Set transitioning delegate on destination view controller
destinationViewController.transitioningDelegate = currentTransition
```
Lastly, in `presentViewController`'s completion handler set `transitionType` to `.Dismiss`, again passing in a presented view controller and a presenting view controller:
```swift
presentViewController(destinationViewController, animated: true) { [weak self] () -> Void in
guard let vc = self,
presentedVC = self?.presentedViewController else {
debugPrint("SplitTransitionAnimatedPresentDismissViewControllerViewController has been deallocated")
return
}
// After presentation has finished, update transitionType on currentTransition
vc.currentTransition?.transitionType = .Dismissal(presentedVC, vc)
}
```
### ZoomPushTransition
`ZoomPushTransition` exposes 2 key properties:
1. `transitionTime` - duration (in seconds) of the transition
2. `scaleChangePct` - a transform which scales the destination view controller's view by `(sx, sy)' at the start of the transition
Set these properties in your view controller's implementation of `UINavigationControllerDelegate`:
```swift
func navigationController(navigationController: UINavigationController, animationControllerForOperation operation: UINavigationControllerOperation, fromViewController fromVC: UIViewController, toViewController toVC: UIViewController) -> UIViewControllerAnimatedTransitioning? {
let zoomPushTransition = ZoomPushTransition()
zoomPushTransition.transitionTime = 0.35
zoomPushTransition.scaleChangePct = 0.33
return zoomPushTransition
}
```