A UIPresentationController and attendant clases for iOS to present a view
controller pinned to an edge of the screen like an action sheet.
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.
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).
SheetPresentation
A
UIPresentationControllerand attendant clases for iOS to present a view controller pinned to an edge of the screen like an action sheet.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.swiftfile.CocoaPods
To use SheetPresentation with CocoaPods, add a dependency to your
Podfile:Then run
pod installand use the generated.xcworkspaceto open your project.Carthage
To use SheetPresentation with Carthage, add a dependency to your
Cartfile:Run
carthage updateto 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
SheetPresentationManagerand set it as thetransitioningDelegateof the view controller you want to present, then set themodalPresentationStyleof the view controller to.custom.Presentation Options
To get the most out of SheetPresentation, you’ll need to set some options on your
SheetPresentationManagerinstances:Corner Options
The corner options specify whether and how the corners of presented views should have their corners rounded:
.roundAllCorners, which takes aCGFloatcorner radius, rounds all corners with the given radius..roundSomeCorners, which takes aCGFloatcorner radius and aCACornerMaskto specify which corner(s) should be rounded..noneleaves the presented view’s corners around.The default value is
.roundAllCornerswith 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
CGFloatvalue. If you specifynil, 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
UIEdgeInsetsorNSDirectionalEdgeInsets. 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
DirectionalViewEdgeorFixedViewEdgetype, depending on if you want to use.leadingand.trailing(recommended) or.leftand.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
.fillto fill the container or.automaticto 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-zeropreferredContentSize.Animation Behavior
When the presented view controller is presented or dismissed, these options control the way that this animation occurs. You can use
.systemto use the default UIKit animations, use.customto provide your own animator objects that conform to theUIViewControllerAnimatedTransitioningprotocol, or use.presentto slide the view controller to or from the given view edge(s).The default value is
.system.