https://github.com/alexeichhorn/pullupmenu
https://github.com/alexeichhorn/pullupmenu
ios menu pullup swift
Last synced: 12 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/alexeichhorn/pullupmenu
- Owner: alexeichhorn
- Created: 2019-09-22T15:46:49.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2024-10-22T18:49:23.000Z (over 1 year ago)
- Last Synced: 2025-06-30T20:55:22.044Z (12 months ago)
- Topics: ios, menu, pullup, swift
- Language: Swift
- Size: 50.8 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# PullUpMenu
PullUpMenu for iOS implemented in Swift.
To show PullUpMenu, use class `PullUpMenuController` like this:
```swift
let menuController = PullUpMenuController()
menuController.items = [
PullUpMenuItem(title: "Item", image: UIImage(named: "item"))
]
menuController.present(in: self)
```
To show `PullUpMenuController` in popover style on a larger screen, present it like this:
```swift
menuController.present(in: self, sourceView: button, sourceRect: button.bounds)
```
Even if you specify a `sourceView` and `sourceRect`, the PullUpMenu only shows in popover mode, when appropriate, that is whenever the horizontal size class is regular. It will switch between modes as the available space changes.
A `PullUpMenuItem` always needs a `title`, but can have optionally a `subtitle`, `image`, `tintColor`, `touchUpInsideHandler` and `isActive` property. E.g.
```swift
PullUpMenuItem(title: "Item", subtitle: "Subtitle", image: UIImage(named: "item"), tintColor: .red, isActive: true, touchUpInsideHandler: { in
// do stuff when pressed
})
```
## Interactive Animation
To add support for interactive opening of the `PullUpMenuController`, you should add something like this to your base view controller:
```swift
var interactiveController: PullUpInteractiveAnimator?
override func viewDidLoad() {
super.viewDidLoad()
interactiveController = PullUpInteractiveAnimator(viewController: self, menuGenerator: {
let menuController = PullUpMenuController()
// add data to menu here
return menuController
})
}
```
## Important
When using `PullUpMenuItem.touchUpInsideHandler`, you should never use a strong refrence to the corresponding `PullUpMenuController` or the view controller it is presented on. This could lead to memory leaks.
Recommended way:
```swift
PullUpMenuItem(title: "Item", touchUpInsideHandler: { [unowned self, unowned menuController] in
self.doStuff()
menuController.doStuff()
})
```