Transforms any view to sliding panel
Panel supports Anchor points, TabBarController and NavigationController, also it has basic TableView support.
Add following to your Podfile:
pod "CTSlidingUpPanel"
pod "CTSlidingUpPanel", '~> 1.0.4'
Make sure to build and clean the project:
import CTSlidingUpPanel
Starting from Version 1.2.0
you can use this library in Objective C projects.
To do this first add: use_frameworks!
- in your podfile. Run pod install and build the project.
To import in Objective C class use:
@import CTSlidingUpPanel;
Example of constructor in Objective C:
[[CTBottomSlideController alloc] initWithParent:self.view bottomView:_testView tabController:nil navController:nil visibleHeight:20];
- Download this repository
- Copy files from lib folder to your project.
- Should be done.
You can view example project to better understand how stuff works.
But here are basic steps with Storyboard:
-
Drag any View(Or Container View) to the parent view. DO NOT give this view any constraints.
-
Create outlet of the view you wish to use as bottom panel
After that in your ViewController:
@IBOutlet weak var bottomView: UIView!
var bottomController:CTBottomSlideController?;
override func viewDidLoad() {
super.viewDidLoad()
//You can provide nil to tabController and navigationController
bottomController = CTBottomSlideController(parent: view, bottomView: bottomView,
tabController: self.tabBarController?,
navController: self.navigationController, visibleHeight: 64)
//0 is bottom and 1 is top. 0.5 would be center
bottomController?.setAnchorPoint(anchor: 0.7)
}
///Added in Version: 1.1.0 - To support Screen orientation changes!
override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
super.viewWillTransition(to: size, with: coordinator)
bottomController?.viewWillTransition(to: size, with: coordinator)
}
And done, view you provided to bottomView should slide up and down.
You can do same without Storyboards. Add new subview to your parent and then provide that subview to CTBottomSlideController. It is recomended that you don't give that subview any constraints.
In this case you should set: Top, Height and other constraints that you want(But don't set the bottom one) to the SlidingView and then use this initializer:
bottomController = CTBottomSlideController(topConstraint: slidingPanelTopConstraint,
heightConstraint: slidingPanelHeightConstraint,
parent: view,
bottomView: bottomView,
tabController: self.tabBarController!,
navController: self.navigationController,
visibleHeight: 64)
It is IMPORTANT that you don't set the bottom constraint of the sliding view or the sliding view will start resizing and that may affect performace.
- Take a Sliding View(View you provided to CTBottomSlideController) and wrap it in a generic UIView.
- Enable Clip to Bounds on the wrapper View
- Set any constraints you want to that wrapper view, place it anywhere resize it as much as you want.
- After that in CTBottomSlideController initializer provide that wrapper as a parrent view instead of root view.
//This is a wrapper view
@IBOutlet weak var parentView: UIView!
//In viewDidLoad() or something
parentView.clipsToBounds = true;
bottomController = CTBottomSlideController(parent: parentView/*instead of view*/, bottomView: bottomView,
tabController: self.tabBarController!,
navController: self.navigationController, visibleHeight: 64)
There are 2 ways of doing this. One is with delegation and other is by using closures.
- Add this to your ViewController
class ViewController: UIViewController, CTBottomSlideDelegate
{...}
- Set viewcontroller as a delegate
bottomController?.delegate = self;
- Implement following methods
func didPanelCollapse();
func didPanelExpand();
func didPanelAnchor();
func didPanelMove(panelOffset: CGFloat);
bottomController?.onPanelExpanded = {
print("Panel Expanded in closure")
}
bottomController?.onPanelCollapsed = {
print("Panel Collapsed in closure")
}
bottomController?.onPanelAnchored = {
print("On Panel anchored")
}
bottomController?.onPanelMoved = { offset in
print("Panel moved in closure " + offset.description)
}
Use this if you want sliding panel to slide up or down depending on ScrollViews offset:
func set(collectionView: UICollectionView)
func set(scrollView: UIScrollView)
func set(table:UITableView)
You can use set(scrollView: UIScrollView)
for any type of scrollview. In reality other methods just call this one
func setExpandedTopMargin(pixels: CGFloat)
func expandPanel();
func anchorPanel();
func closePanel();
func hidePanel();
func setSlideEnabled(bool) // Enable or disable sliding
Use this to check panels state
bottomController?.currentState
State can be
.collapsed
.expanded
.anchored
.hidden