https://github.com/jakelawson1/FlickToDismiss
A basic UIViewController class that presents a UIView which can be dismissed by flicking it off the screen.
https://github.com/jakelawson1/FlickToDismiss
Last synced: 3 months ago
JSON representation
A basic UIViewController class that presents a UIView which can be dismissed by flicking it off the screen.
- Host: GitHub
- URL: https://github.com/jakelawson1/FlickToDismiss
- Owner: jakelawson1
- License: mit
- Created: 2016-06-04T18:09:19.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2016-10-04T06:51:56.000Z (over 8 years ago)
- Last Synced: 2025-03-21T09:18:25.104Z (3 months ago)
- Language: Swift
- Size: 2.11 MB
- Stars: 208
- Watchers: 3
- Forks: 13
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# FlickToDismiss

## Requirements
- iOS 8.0+
- Xcode 7.3## Installation
### CocoaPods
[CocoaPods](http://cocoapods.org) is a dependency manager for Cocoa projects. You can install it with the following command:
```bash
$ gem install cocoapods
```To integrate FlickToDismiss into your Xcode project using CocoaPods, specify it in your `Podfile`:
```ruby
pod 'FlickToDismiss', '~> 0.9'
```Then, run the following command:
```bash
$ pod install
```### Manual
Add [FlickToDismissViewController.swift](Source/FlickToDismissViewController.swift) to your project in Xcode.
## Usage
### Interface Builder
1. Drag a new `UIViewController` object onto your storyboard.
2. Set the class to `FlickToDismissViewController`.
3. Drag a `UIView` object onto the View Controller.
4. Add any necessary constraints.
5. Connect the `flickableView` outlet to the `UIView` in the Connections inspector.
6. Job done.### Programatically
```swift
let viewToFlick = UIView(frame: CGRect(x: 0, y: 0, width: 280, height: 300))
viewToFlick.backgroundColor = .whiteColor()
// Optional - See FlickToDismissOption for available options.
let options: [FlickToDismissOption] = [
.Animation(.Scale),
.BackgroundColor(UIColor(white: 0.0, alpha: 0.8))
]
let vc = FlickToDismissViewController(flickableView: viewToFlick, options: options)
vc.modalTransitionStyle = .CrossDissolve
vc.modalPresentationStyle = .OverFullScreen
presentViewController(vc, animated: true, completion: nil)
```#### Hint - Subclassing UIView
Since Auto Layout sizes views according to their frames, it incorrectly assumes it has a larger space to lay things out when a view is rotated. To correct this we need to supply the method `alignmentRectForFrame()` in the view subclass:
```swift
override func alignmentRectForFrame(frame: CGRect) -> CGRect {
return bounds
}
```## License
FlickToDismiss is licensed under the MIT License. See [LICENSE](LICENSE) for details.
Let me know if you use FlickToDismiss in your projects, I would love to know!