Giter VIP home page Giter VIP logo

sheetpresentation's Introduction

SheetPresentation

A UIPresentationController and attendant clases for iOS to present a view controller pinned to an edge of the screen like an action sheet.

Version Documentation Carthage compatible Swift Package Manager License Platform

Installation

Swift Package Manager

To use SheetPresentation with the Swift Package Manager, add it as a dependency to your project from within Xcode or as a dependency in your Package.swift file.

CocoaPods

To use SheetPresentation with CocoaPods, add a dependency to your Podfile:

target 'MyAwesomeApp' do
  pod 'SheetPresentation'
end

Then run pod install and use the generated .xcworkspace to open your project.

Carthage

To use SheetPresentation with Carthage, add a dependency to your Cartfile:

github "Detroit-Labs/SheetPresentation"

Run carthage update to build the framework. Then follow the rest of the steps in Carthage’s README to add the framework to your project, configure a Run Script build phase, etc.

Using SheetPresentation

To use SheetPresentation, create a SheetPresentationManager and set it as the transitioningDelegate of the view controller you want to present, then set the modalPresentationStyle of the view controller to .custom.

let manager = SheetPresentationManager() // Save this reference somewhere
let viewControllerToPresent = 
viewControllerToPresent.transitioningDelegate = manager
viewControllerToPresent.modalPresentationStyle = .custom

present(viewControllerToPresent, animated: true, completion: nil)

Presentation Options

To get the most out of SheetPresentation, you’ll need to set some options on your SheetPresentationManager instances:

Corner Options

The corner options specify whether and how the corners of presented views should have their corners rounded:

  • .roundAllCorners, which takes a CGFloat corner radius, rounds all corners with the given radius.
  • .roundSomeCorners, which takes a CGFloat corner radius and a CACornerMask to specify which corner(s) should be rounded.
  • .none leaves the presented view’s corners around.

The default value is .roundAllCorners with a radius of 10 points.

Dimming View Alpha

SheetPresentation can place a black dimming view behind the presented view. To control its opacity, you can specify a CGFloat value. If you specify nil, then a dimming view will not be placed behind the presented view and touches will be forwarded to the presenting view controller if they fall outside the presented view.

The default value is 50% opacity.

Edge Insets

The edge insets control the distance between the presenting view controller and the presented view. You can use either UIEdgeInsets or NSDirectionalEdgeInsets. This value is combined with the safe area, so if you use an inset that is less than the safe area, the safe area’s inset will be used.

The default value is 20 points on all sides.

Ignored Edges for Margins

You can specify an array of edges to ignore for margins (including the safe area) when performing layout. Edges can be either the DirectionalViewEdge or FixedViewEdge type, depending on if you want to use .leading and .trailing (recommended) or .left and .right.

The default value is an empty array to ignore no edges.

Presentation Layout

The presentation layout controls how SheetPresentation positions the presented view within the presentation container. Specify both horizontal and vertical layouts, which can either be .fill to fill the container or .automatic to automatically size the presented view. The automatic layouts must specify either vertical or horizontal alignment to control where the presented view is placed relative to the container.

The default value is a vertical layout of .automatic(.bottom) and a horizontal layout of .fill.

Requirements

To correctly compute the height of the presented view controller when using automatic layouts, it must either satisfy Auto Layout constraints for a height using systemLayoutSizeFitting(_:withHorizontalFittingPriority:verticalFittingPriority:) or have a non-zero preferredContentSize.

Animation Behavior

When the presented view controller is presented or dismissed, these options control the way that this animation occurs. You can use .system to use the default UIKit animations, use .custom to provide your own animator objects that conform to the UIViewControllerAnimatedTransitioning protocol, or use .present to slide the view controller to or from the given view edge(s).

The default value is .system.

sheetpresentation's People

Contributors

dependabot[bot] avatar jshier avatar marcsteven avatar nwdl avatar slaunchaman avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

sheetpresentation's Issues

Vertical layout automatic always have height 0 when using UIScrollView inside the sheet.

Thank you for your awesome work.
I found there is a use-case that cause the height always is 0 when using UIScrollView inside the sheet ViewController. Could you please help to take a look and suggest how to fix it properly?

Below is the sample ScrollView within ViewController. This ViewController works normal with default presentation.

import UIKit

final class Label: UILabel {
    init(_ text: String) {
        super.init(frame: .zero)
        self.text = text

        textColor = .darkText
    }

    @available(*, unavailable)
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}

final class SampleScrollViewController: UIViewController {
    override func viewDidLoad() {
        super.viewDidLoad()

        let scrollView = UIScrollView()

        let stackView = UIStackView(arrangedSubviews: (1...10).map { Label("Text \($0)") })
        stackView.axis = .vertical
        stackView.spacing = 8
        scrollView.addSubview(stackView)
        view.addSubview(scrollView)

        stackView.translatesAutoresizingMaskIntoConstraints = false
        scrollView.translatesAutoresizingMaskIntoConstraints = false

        NSLayoutConstraint.activate([
            stackView.topAnchor.constraint(equalTo: scrollView.topAnchor),
            stackView.bottomAnchor.constraint(equalTo: scrollView.bottomAnchor),
            stackView.leadingAnchor.constraint(equalTo: scrollView.leadingAnchor),
            stackView.trailingAnchor.constraint(equalTo: scrollView.trailingAnchor),
            stackView.widthAnchor.constraint(equalTo: view.widthAnchor),
        ])

        NSLayoutConstraint.activate([
            scrollView.topAnchor.constraint(equalTo: view.topAnchor),
            scrollView.bottomAnchor.constraint(equalTo: view.bottomAnchor),
            scrollView.leadingAnchor.constraint(equalTo: view.leadingAnchor),
            scrollView.trailingAnchor.constraint(equalTo: view.trailingAnchor),
        ])
    }
}

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.