2019-09-23 21:16:52 +00:00
|
|
|
//
|
|
|
|
// ViewController.swift
|
|
|
|
// SheetImagePickerTest
|
|
|
|
//
|
|
|
|
// Created by Shadowfacts on 9/23/19.
|
|
|
|
// Copyright © 2019 Shadowfacts. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
import UIKit
|
|
|
|
import SheetImagePicker
|
|
|
|
|
|
|
|
class ViewController: UIViewController {
|
|
|
|
|
|
|
|
override func viewDidLoad() {
|
|
|
|
super.viewDidLoad()
|
|
|
|
// Do any additional setup after loading the view.
|
2019-09-24 15:48:40 +00:00
|
|
|
view.backgroundColor = .green
|
2019-09-23 21:16:52 +00:00
|
|
|
|
|
|
|
let content = UIViewController()
|
|
|
|
content.view.translatesAutoresizingMaskIntoConstraints = false
|
|
|
|
content.view.backgroundColor = .red
|
|
|
|
let sheet = SheetContainerViewController(content: content)
|
2019-09-24 15:43:46 +00:00
|
|
|
sheet.delegate = self
|
|
|
|
sheet.detents = [.bottom, .middle, .top]
|
2019-09-24 15:48:40 +00:00
|
|
|
// sheet.view.backgroundColor = .blue
|
2019-09-23 21:16:52 +00:00
|
|
|
|
|
|
|
addChild(sheet)
|
|
|
|
sheet.didMove(toParent: self)
|
|
|
|
view.addSubview(sheet.view)
|
|
|
|
NSLayoutConstraint.activate([
|
|
|
|
sheet.view.leadingAnchor.constraint(equalTo: view.leadingAnchor),
|
|
|
|
sheet.view.trailingAnchor.constraint(equalTo: view.trailingAnchor),
|
|
|
|
sheet.view.topAnchor.constraint(equalTo: view.topAnchor),
|
|
|
|
sheet.view.bottomAnchor.constraint(equalTo: view.bottomAnchor)
|
|
|
|
])
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2019-09-24 15:43:46 +00:00
|
|
|
extension ViewController: SheetContainerViewControllerDelegate {
|
|
|
|
func sheetContainer(_ sheetContainer: SheetContainerViewController, willSnapToDetent detent: Detent) -> Bool {
|
|
|
|
if detent == .bottom {
|
|
|
|
UIView.animate(withDuration: 0.35, animations: {
|
|
|
|
sheetContainer.view.transform = CGAffineTransform(translationX: 0, y: sheetContainer.view.bounds.height)
|
|
|
|
}, completion: { (finished) in
|
|
|
|
sheetContainer.removeFromParent()
|
|
|
|
sheetContainer.didMove(toParent: nil)
|
|
|
|
sheetContainer.view.removeFromSuperview()
|
|
|
|
})
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|