Skip to content

You can dismiss modal viewcontroller like Facebook Messenger by pulling scrollview or navigationbar in Swift.

License

Notifications You must be signed in to change notification settings

Sam-Spencer/PullToDismiss

 
 

Repository files navigation

PullToDismiss

PullToDismiss provides dismiss modal viewcontroller function like Facebook Messenger by pulling scrollview or navigationbar with smooth and rich background effect.

GitHub release Language Carthage Compatible CocoaPods

sample blur sample
gif gif

Appetize.io Demo

Features

  • Supports all types of scrolling views:
    • UIScrollView
    • UITableView
    • UICollectionView
    • UIWebView
    • WKWebView
  • Customizable:
    • Dismiss background color
    • Alpha and blur strength
    • Height percentage for auto-dismiss
  • Available in UIViewController and UINavigationController
  • Automatically adds pan gesture to the navigation bar
  • Blur effect support

Usage

Getting Started

(1) Setup PullToDismiss

import PullToDismiss

class SampleViewController: UIViewController {
    @IBOutlet private weak var tableView: UITableView!
    private var pullToDismiss: PullToDismiss?
    override func viewDidLoad() {
        super.viewDidLoad()
        pullToDismiss = PullToDismiss(scrollView: tableView)
    }
}

(2) Create view controller and set modalPresentationStyle. Then present view controller

let vc = SampleViewController()
let nav = UINavigationController(rootViewController: vc)
nav.modalPresentationStyle = .overCurrentContext

self.present(nav, animated: true, completion: nil)

Use (UIScrollView|UITableView|UICollectionView)Delegate

You can use all scroll view's delegate by set pullToDismiss.delegate.

import PullToDismiss

class SampleViewController: UIViewController {
    @IBOutlet private weak var tableView: UITableView!
    private var pullToDismiss: PullToDismiss?
    override func viewDidLoad() {
        super.viewDidLoad()
        pullToDismiss = PullToDismiss(scrollView: tableView)
        pullToDismiss?.delegate = self
    }
}

extension SampleViewController: UITableViewDelegate {
    func scrollViewDidScroll(_ scrollView: UIScrollView) {
        // ...
    }

    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        // ...
    }
}

Customize

You can customize backgroundEffect, dismissableHeightPercentage:

Shadow background effet

  • background (default: ShadowEffect.default, [color: black, alpha: 0.8])

img1

pullToDismiss?.background = ShadowEffect(color: .red, alpha: 0.5) // color: red, alpha: 0.5

Blur background effect

New feature for v1.0.

gif

// preset blur (.extraLight, .light, .dark)
pullToDismiss?.background = BlurEffect.extraLight

// set custom Blur
pullToDismiss?.background = BlurEffect(color: .red, alpha: 0.5, blurRadius: 40.0, saturationDeltaFactor: 1.8)

dismissableHeightPercentage

img2

// to pull half size of view controller, dismiss view controller.
pullToDismiss?.dismissableHeightPercentage = 0.5

Requirements

  • iOS 11.0+
  • Xcode 11.0+
  • Swift 5.0+

Installation

Swift Package Manager

Add the following in Xcode's Swift Package Manager and specify at least v2.3.0

https://github.com/Sam-Spencer/PullToDismiss.git

Carthage

  • Add the following to your Cartfile:
github "sgr-ksmt/PullToDismiss"
  • Run carthage update
  • Add the framework as described.

Details: Carthage Readme

CocoaPods

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

pod 'PullToDismiss', '~> 2.2'

Then, run pod install.

Manually Install

Download all *.swift files and put your project.

About

You can dismiss modal viewcontroller like Facebook Messenger by pulling scrollview or navigationbar in Swift.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Swift 94.5%
  • Ruby 2.8%
  • Objective-C 2.7%