Coder Social home page Coder Social logo

stuffrabbit / wkpulltodismiss Goto Github PK

View Code? Open in Web Editor NEW
9.0 2.0 0.0 21.98 MB

Simple pull to dismiss interactive transition with (scroll-)views in just one line.

License: MIT License

Swift 89.60% Ruby 10.40%
ios swift uiviewcontroller interactive-transition custom-transitions uiscrollview

wkpulltodismiss's Introduction

WKPullToDismiss

Version License Platform

Example

To run the example project, clone the repo, and run pod install from the Example directory first.

Requirements

Swift 5.0

Installation

WKPullToDismiss is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod 'WKPullToDismiss'

Demo

Output sample

Quick start

Create an object of type WKPullToDismiss and pass the view controller to be dismissed, as well as the view which is supposed to trigger the transition.

pullToDismiss = WKPullToDismiss(viewController: self, dismissView: view)

If you pass UIScrollView as dismissView parameter, the scrollviews UIPanGestureRecognizer will be used to trigger the dismissal. Otherwise, a new UIPanGestureRecognizer will be created and added to the dismissView. Make sure that other gesture recognizers do not interfere. Additionally, make sure to hold a reference to this object in your view controller.

Important: The object WKPullToDismiss will set itself as the transitioning delegate of the passed viewcontroller upon initialization. There is no more action required. However, in case you have multiple transitions to handle and want to set a custom transitionin delegate, read the chapter Custom transitioning delegate.

Advanced

You can make the following adjustments at runtime:

  • customScrollTriggerValue: CGFloat? If you are using a Scrollview as view for dismissal you can set a custom offset (Y value) at which the transition is supposed to be triggered. By default the respective Scrollview's contentInset.top value is used.
  • isEnabled: Bool Defines if the pan gesture recognizer is supposed to trigger the transition. Default is true.
  • interactionController = WKPullToDismissInteractionController(). The interaction controller for the transition. You can modify its dismissThreshold property. It defines the percentage which has to be completed in order to finish the transition. Default value is 0.3.
  • transitionDuration: TimeInterval. The duration of the transition. Default is 0.5 seconds.

Custom transitioning delegate

The object WKPullToDismiss will set itself as the transitioning delegate of the passed view controller upon initialization. You can still change the viewcontrollers transitioning delegate afterwards to another object e.g. if you want to handle additional tranistions. This, however, requires to pass the given interaction controller and the anmiation controller of this library at the given time to the respective methods of UIViewControllerTransitioningDelegate:

func animationController(forDismissed dismissed: UIViewController) -> UIViewControllerAnimatedTransitioning?`
func interactionControllerForDismissal(using animator: UIViewControllerAnimatedTransitioning) -> UIViewControllerInteractiveTransitioning?

This library provides the classes WKPullToDismissInteractionController and WKPullToDismissAnimationController, which have to be returned in those methods in order to make the transition work.

Feedback

Let me know if you have any questions. Either directly or via github. I will try to respond asap.

Author

Wojtek Kordylewski

License

WKPullToDismiss is available under the MIT license. See the LICENSE file for more info.

wkpulltodismiss's People

Contributors

stuffrabbit avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.