Add background dimming view
This commit is contained in:
parent
1eea2313cd
commit
9ddd39da4c
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue