Coder Social home page Coder Social logo

ilhamicngz / handyviewcontroller Goto Github PK

View Code? Open in Web Editor NEW

This project forked from mobven/handyviewcontroller

0.0 0.0 0.0 4.69 MB

View controller transitioning allowing self-sizing presented view controller to be dismissed by swiping down.

License: MIT License

Swift 100.00%

handyviewcontroller's Introduction

Pod License SwiftPM compatible codebeat badge

View controller transitioning allowing self-sizing presented view controller to be dismissed by swiping down.

Examples

Custom Content UITableVoew Full Screen

Requirements

  • iOS 10.0+
  • Xcode 11+
  • Swift 5.2+

Installation

HandyViewController is distributed with Swift Package Manager which is the only official distribution tool by Apple. You can add HandyViewController to your project from Xcode's File > Swift Packages > Add Package Dependency menu with its github URL:

https://github.com/mobven/HandyViewController.git

Usage

Basically, to achieve HandyViewController presentation, you set transitioningDelegate of your view controller to HandyTransitioningDelegate. There are two options while initializing HandyTransitioningDelegate:

Content size

Presented view controller must have necessary constraints (from top to bottom) to allow HandyViewController to calculate its height.

let controller = storyboard!.instantiateViewController(withIdentifier: "ViewController")
let transitioningDelegate = HandyTransitioningDelegate(from: self, to: controller)
controller.modalPresentationStyle = .custom
controller.transitioningDelegate = transitioningDelegate
present(controller, animated: true)

Full Screen

View controller displayed full screen with a small padding in the top.

let controller = storyboard!.instantiateViewController(withIdentifier: "ViewController")
let transitioningDelegate = HandyTransitioningDelegate(from: self, to: controller, contentMode: .fullScreen)
controller.modalPresentationStyle = .custom
controller.transitioningDelegate = transitioningDelegate
present(controller, animated: true)

ScrollView events

If presented view controller contains any UIScrollView (eg. UITableView, UICollectionView) that has no specifed content height, allow HandyViewController to calculate its size by:

override func viewDidLoad() {
    super.viewDidLoad()
    registerHandyScrollView(tableView)
}

HandyViewController provides swipe-to-dismiss feature with scroll events. To achieve this behavior, in your presented view controller:

extension DetailsViewController: UIScrollViewDelegate {

    func scrollViewDidScroll(_ scrollView: UIScrollView) {
        handyScrollViewDidScroll(scrollView)
    } 

    func scrollViewWillEndDragging(_ scrollView: UIScrollView, withVelocity velocity: CGPoint,
                                   targetContentOffset: UnsafeMutablePointer<CGPoint>) {
        handyScrollViewWillEndDragging(scrollView, withVelocity: velocity)
    }
}

StackView usage

During usage we've faced content size calculation issues with presented view controllers containing UIStackView with fill distribution and alignment attributes. As a workaround to this issue HandyViewController adds an empty footer view to your stack view, which is invisible. You can achieve this by calling:

override func viewDidLoad() {
    super.viewDidLoad()
    registerHandyStackView(stackView)
}

What's next

  • Allow view controller to interrupt swipe-to-dismiss.
  • Tests in iPads.
  • Swipe-to-dismiss indicator in top of the screen.
  • iOS 13 modal presentation style for full-screen presented view controllers where presenting view controller frame decreased in background.
  • Unit Tests.

Developed with ๐Ÿ–ค at Mobven

handyviewcontroller's People

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.