FloatingPanel
FloatingPanel copied to clipboard
lock the panel and prevent going to tip state?
Is there any to lock the panel and prevent going to tip state and support only half and full?
I am using the Maps example.
How do you display panel(s)?
- Add as child view controllers
How many panels do you displays?
- 1
Environment
Library version latest
Installation method
- CocoaPods
iOS version(s) 14
Xcode version latest
Is there any to lock the panel and prevent going to tip state and support only half and full?
Does lock the panel mean that a panel doesn't become the tip state, doesn’t it?
If so, yes, you can define a layout object adopting FloatingPanelLayout to change supported states of a panel and then assign the instance to FloatingPanelLayout.layout.
Here is a short way to define a layout object inherited from FloatingPanelBottomLayout.
class MyPanelLayout: FloatingPanelBottomLayout {
override var anchors: [FloatingPanelState : FloatingPanelLayoutAnchoring] {
return [
.full: FloatingPanelLayoutAnchor(absoluteInset: 88.0, edge: .bottom, referenceGuide: .safeArea),
.half: FloatingPanelLayoutAnchor(absoluteInset: 216.0, edge: .top, referenceGuide: .safeArea),
]
}
}
I removed. .tip from anchor here: https://github.com/SCENEE/FloatingPanel/blob/master/Examples/Maps/Maps/ViewController.swift#L295 but still can scroll to the tup state.
Aha, I might be able to understand your expectation. How about this code?(please use this with the above layout) You can control a panel move in floatingPanelDidMove delegate method. This code prevents moving a pane under a position of half state.
func floatingPanelDidMove(_ vc: FloatingPanelController) {
let loc = vc.surfaceLocation
if vc.isAttracting == false {
let maxY = vc.surfaceLocation(for: .half).y
vc.surfaceLocation = CGPoint(x: loc.x, y: min(loc.y, maxY))
}
}
tried several methods but not working. The panel keeps going to the tip when scrolled, while i want it to stay fixed and locked in half and can be dragged to full state.
You look use a top positioned panel. The above example code is for a bottom positioned panel. So in addition to the change of your comment, please try this in Maps example app.
class SearchPanelPadDelegate: NSObject, FloatingPanelControllerDelegate, UIGestureRecognizerDelegate {
...
func floatingPanelDidMove(_ vc: FloatingPanelController) {
let loc = vc.surfaceLocation
if vc.isAttracting == false {
let minY = vc.surfaceLocation(for: .half).y
vc.surfaceLocation = CGPoint(x: loc.x, y: max(loc.y, minY))
}
}
}
The behavior is weird now. Were you able to test in the Map example? Thanks.
Hmm... yes, I was of course. I'm having trouble understanding your situation. You said as below.
I removed. .tip from anchor here: https://github.com/SCENEE/FloatingPanel/blob/master/Examples/Maps/Maps/ViewController.swift#L295
But the layout removed .tip is not valid because the initial state is tip. Which of panel did you want to modify a layout in Map example?
The search one declared here: https://github.com/SCENEE/FloatingPanel/blob/master/Examples/Maps/Maps/ViewController.swift#L11
Hi @alouanemed, I just added the below lines and it is working for me. You can also give it a try.
extension FloatingPanelBottomLayout { open var anchors: [FloatingPanelState: FloatingPanelLayoutAnchoring] { return [ .full: FloatingPanelLayoutAnchor(absoluteInset: 18.0, edge: .top, referenceGuide: .safeArea), .half: FloatingPanelLayoutAnchor(fractionalInset: 0.5, edge: .bottom, referenceGuide: .safeArea) ] } }