SheetImagePicker/SheetImagePickerTest/ViewController.swift

54 lines
1.8 KiB
Swift

//
// 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.
let content = UIViewController()
content.view.translatesAutoresizingMaskIntoConstraints = false
content.view.backgroundColor = .red
let sheet = SheetContainerViewController(content: content)
sheet.delegate = self
sheet.detents = [.bottom, .middle, .top]
sheet.view.backgroundColor = .blue
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)
])
}
}
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
}
}