FloatingPanel https://github.com/SCENEE/FloatingPanel#add-a-floating-panel-as-a-child-view-controller
Add a floating panel as a child view controller
When added as a child VC, it is basically assumed that it will not be deleted by swiping down. If you write fpc.isRemovalInteractionEnabled = true
here, the parent view on the back will scroll when scrolling, or if you close it with a down swipe, the parent view button will not work and you will not be able to open the floating panel again. ..
Present a floating panel as a modality
So basically, it's better to use this which is the standard behavior of iOS and close it with a down swipe.
import FloatingPanel
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
fpc = FloatingPanelController(delegate: self)
fpc.layout = MyFloatingPanelLayout()
let contentVC == CommentViewController()
// or let contentVC = CommentViewController.fromStoryboard()
fpc.set(contentViewController: contentVC)
fpc.isRemovalInteractionEnabled = true // Let it removable by a swipe-down
fpc.track(scrollView: contentVC.tableView) // .Make the contentVC tableView scrollable when it becomes full
}
@IBAction func didTapCommentButton(_ sender: Any) {
self.present(fpc, animated: true, completion: nil)
}
}
class MyFloatingPanelLayout: FloatingPanelLayout {
let position: FloatingPanelPosition = .bottom
let initialState: FloatingPanelState = .half
var anchors: [FloatingPanelState: FloatingPanelLayoutAnchoring] {
return [
.half: FloatingPanelLayoutAnchor(fractionalInset: 0.5, edge: .bottom, referenceGuide: .safeArea),
]
}
}
At first, hide it with let initialState = .hidden
, and when the button is pressed, call the following from the bottom.
self.fpc.move(to: .half, animated: true)
It should be a code that hides in the following form when you press the close button (I prepared it instead because it can not be closed by swiping down).
self.fpc.move(to: .hide, animated: true)
Recommended Posts