* The latest **public** build of [Xcode](https://developer.apple.com/xcode/)(and a compatible Mac). *Currently Xcode 8* (You can get this from the [Mac App Store](https://itunes.apple.com/us/app/xcode/id497799835?mt=12) if you want easy updates)
* The latest **public** build of [Xcode](https://developer.apple.com/xcode/)(and a compatible Mac). *Currently Xcode 9* (You can get this from the [Mac App Store](https://itunes.apple.com/us/app/xcode/id497799835?mt=12) if you want easy updates)
* The latest **public** release of Swift. *Currently Swift 3.0* (bundled with Xcode)
* The latest **public** release of Swift. *Currently Swift 4.0* (bundled with Xcode)
* Cocoapods, for dependency management. You can install this by running `sudo gem install cocoapods` in your terminal. (Dependency management may change in the future)
# Uncomment this line to define a global platform for your project
# platform :ios, '8.0'
# Uncomment this line if you're using Swift
platform:ios,'11.0'
use_frameworks!
target'WhatsOpen'do
pod'RealmSwift'
pod'ObjectMapper','~> 2.2'
pod'ObjectMapper','~> 3.0'
#pod 'Segmentio', '~> 2.1'
pod'DeckTransition','~> 1.4.0'
end
...
...
@@ -20,4 +24,7 @@ post_install do |installer|
config.build_settings['SWIFT_VERSION']='3.1'
end
end
end
require'fileutils'
FileUtils.cp_r('Pods/Target Support Files/Pods-WhatsOpen/Pods-WhatsOpen-Acknowledgements.plist','WhatsOpen/Settings.bundle/Acknowledgements.plist',:remove_destination=>true)
To install DeckTransition using [CocoaPods](http://cocoapods.org), add the following line to your Podfile:
```
pod 'DeckTransition', '~> 1.0'
```
### Carthage
To install DeckTransition using [Carthage](https://github.com/Carthage/Carthage), add the following line to your Cartfile:
```
github "HarshilShah/DeckTransition" ~> 1.0
```
## Documentation
You can find [the docs here](https://harshilshah.github.io/DeckTransition"Documentation"). Documentation is generated with [Jazzy](https://github.com/realm/jazzy), and hosted on [GitHub Pages](https://pages.github.com).
## Usage
### Basics
Set `modalPresentationCapturesStatusBarAppearance` to `true` in your modal view controller, and override the `preferredStatusBarStyle` variable to return `.lightContent`.
The background color for the presentation can be changed by changing the `backgroundColor` property of the `window`. This is `.black` by default.
### Presentation
The transition can be called from code or using a storyboard.
To use via storyboards, just setup a custom segue (`kind` set to `custom`), and set the `class` to `DeckSegue`.
Hereʼs a snippet showing usage via code. Just replace `ModalViewController()` with your view controller's class and youʼre good to go.
```swift
letmodal=ModalViewController()
lettransitionDelegate=DeckTransitioningDelegate()
modal.transitioningDelegate=transitionDelegate
modal.modalPresentationStyle=.custom
present(modal,animated:true,completion:nil)
```
### Dismissal
This is the part where it gets a bit tricky. If youʼve got a fixed-sized i.e. non-scrolling modal, feel free to just skip the rest of this section. Swipe-to-dismiss will work perfectly for you
For modals which have a vertically scrolling layout, the dismissal gesture should be fired only when the view is scrolled to the top. To achieve this behaviour, you need to modify the `isDismissEnabled` property of the `DeckTransitioningDelegate`. (You can also set `isDismissEnabled` to false if you want to disable the swipe-to-dismiss UI.)
The one issue with doing this in response to the scrollviewʼs `contentOffset` is momentum scrolling. When the user pans from top the bottom, once the top of the scrollview is reached (`contentOffset.y` is 0), the dismiss gesture should take over and the scrollview should stop scrolling, not showing the usual iOS bounce effect. The dismiss gesture, however, only responds to pans and not swipes, so should you swipe and not pan, the scrollview will scroll to the top and abruptly stop (as the `contentOffset.y` is 0) without the usual iOS bounce effect.
I've found a temporary workaround for this, the code for this can be found below. Itʼs a bit messy right now, but is the only workaround Iʼve found for this issue (so far). It has one caveat, in that it fails utterly miserably when using with a scrollview whose `backgroundColor` isnʼt `.clear`.
Iʼll update this project if/when I find a better solution.
#### Dismissal code for scrolling modals
First up, make your modal view controller conform to `UIScrollViewDelegate` (or `UITableViewDelegate`/`UITextFieldDelegate`, as the case may be), and assign self as the scrollview's `delegate`.
Next, add this method to your modal view controller, swapping in your scrollviewʼs variable for `textView`.
// If the user has panned to the top, the scrollview doesnʼt bounce and
// the dismiss gesture is enabled.
scrollView.bounces=false
delegate.isDismissEnabled=true
}
}
}
}
```
### Snapshots
For a variety of reasons, and especially because of iOS 11's safe area layout, DeckTransition uses a snapshot of your presenting view controller's view instead of using the view directly. This view is automatically updated whenever the frame is resized.
However, there can be some cases where you might want to update the snapshot view by yourself, and this can be achieved using the following one line snippet:
It's worth noting that updating the snapshot is an expensive process and should only be used if necessary, for example if you are updating your entire app's theme.
## Apps Using DeckTransition
-[Petty](https://zachsim.one/projects/petty) by [Zach Simone](https://twitter.com/zachsimone)
-[Bitbook](https://bitbookapp.com) by [Sammy Gutierrez](https://sammygutierrez.com)
-[BookPlayer](https://github.com/GianniCarlo/Audiobook-Player) by [Gianni Carlo](https://twitter.com/GCarlo89)
Feel free to submit a PR if you’re using this library in your apps
## Author
Written by [Harshil Shah](https://twitter.com/HarshilShah1910)
## License
DeckTransition is available under the MIT license. See the LICENSE file for more info.