Bottom sheet popover built with Swift & UIKit
CocoaPods is a dependency manager for Cocoa projects. To integrate BottomSheet into your project using CocoaPods, specify it in your Podfile
:
pod 'IDBottomSheet'
After that use pod install
command in your terminal.
If you prefer not to use any dependency managers, you can integrate BottomSheet into your project manually by downloading the desired release and copying the Sources
directory.
Subclass BottomSheetViewController
, then override viewDidLoad like this:
class ViewController: BottomSheetViewController {
override func viewDidLoad() {
viewController = BottomSheetContentsViewController() //your view controller
isHalfPresentationEnabled = true //or false
super.viewDidLoad()
}
}
Note that super.viewDidLoad()
must be called after you set BottomSheetViewController properties.
To enable half presentation set isHalfPresentationEnabled
property to true
.
isHalfPresentationEnabled = false | isHalfPresentationEnabled = true |
---|---|
To change animation duration set animationDuration
property.
To modify popover startHeight & endHeight call setupSizeWith(startHeight: CGFloat, endHeight: CGFloat)
method.
To modify popover corner radius for all states call setupCornerRadiusForState(collapsed: CGFloat, halfPresented: CGFloat, expanded: CGFloat)
method.
To modify popover corner radius for a single state call setupCornerRadiusForState(state: State, value: CGFloat)
method.
BottomSheet recognizes taps on the handler and recognizes swipes across the entire view. In addition, BottomSheet analyzes how fast you swipe and where you swipe. This means that if you swipe slowly and the swipe endpoint is less than half of the popup's height, the presentation will be canceled. If you swipe quickly, the popup will always be presented.
This repository contains example where you can see how BottomSheet can be used for presenting Apple Music player popover.
BottomSheet is available under the MIT license, see the LICENSE file for more information.