From 9ddd39da4cbf4534546615346e26f92cf766d664 Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Tue, 24 Sep 2019 11:48:40 -0400 Subject: [PATCH] Add background dimming view --- .../SheetContainerViewController.swift | 20 ++++++++++++++++--- SheetImagePickerTest/ViewController.swift | 3 ++- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/SheetImagePicker/SheetContainerViewController.swift b/SheetImagePicker/SheetContainerViewController.swift index a523a58..82d6146 100644 --- a/SheetImagePicker/SheetContainerViewController.swift +++ b/SheetImagePicker/SheetContainerViewController.swift @@ -31,13 +31,15 @@ public class SheetContainerViewController: UIViewController { var topDetent: (detent: Detent, offset: CGFloat) { return detents.map { ($0, $0.offset(in: view)) }.min(by: { $0.1 < $1.1 })! } + + public var minimumDetentJumpVelocity: CGFloat = 500 + public var maximumStretchDistance: CGFloat = 15 var topConstraint: NSLayoutConstraint! lazy var initialConstant: CGFloat = view.bounds.height / 2 - public var minimumDetentJumpVelocity: CGFloat = 500 - public var maximumStretchDistance: CGFloat = 15 - + var dimmingView: UIView! + public init(content: UIViewController) { self.content = content @@ -51,6 +53,18 @@ public class SheetContainerViewController: UIViewController { override public func viewDidLoad() { super.viewDidLoad() + dimmingView = UIView() + dimmingView.translatesAutoresizingMaskIntoConstraints = false + dimmingView.backgroundColor = .systemGray + dimmingView.alpha = 0.5 + view.addSubview(dimmingView) + NSLayoutConstraint.activate([ + dimmingView.leadingAnchor.constraint(equalTo: view.leadingAnchor), + dimmingView.trailingAnchor.constraint(equalTo: view.trailingAnchor), + dimmingView.topAnchor.constraint(equalTo: view.topAnchor), + dimmingView.bottomAnchor.constraint(equalTo: view.bottomAnchor) + ]) + addChild(content) content.didMove(toParent: self) view.addSubview(content.view) diff --git a/SheetImagePickerTest/ViewController.swift b/SheetImagePickerTest/ViewController.swift index 50f3380..3a90937 100644 --- a/SheetImagePickerTest/ViewController.swift +++ b/SheetImagePickerTest/ViewController.swift @@ -14,6 +14,7 @@ class ViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view. + view.backgroundColor = .green let content = UIViewController() content.view.translatesAutoresizingMaskIntoConstraints = false @@ -21,7 +22,7 @@ class ViewController: UIViewController { let sheet = SheetContainerViewController(content: content) sheet.delegate = self sheet.detents = [.bottom, .middle, .top] - sheet.view.backgroundColor = .blue +// sheet.view.backgroundColor = .blue addChild(sheet) sheet.didMove(toParent: self)