https://github.com/cbess/partialmodalpresentationcontroller
A presentation controller that displays a view controller in a modal overlay style
https://github.com/cbess/partialmodalpresentationcontroller
ios swift
Last synced: over 1 year ago
JSON representation
A presentation controller that displays a view controller in a modal overlay style
- Host: GitHub
- URL: https://github.com/cbess/partialmodalpresentationcontroller
- Owner: cbess
- License: mit
- Created: 2020-05-04T02:35:38.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2020-05-04T02:45:06.000Z (about 6 years ago)
- Last Synced: 2025-01-17T04:45:18.470Z (over 1 year ago)
- Topics: ios, swift
- Language: Swift
- Size: 5.86 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# PartialModalPresentationController
A [presentation controller](https://developer.apple.com/documentation/uikit/uipresentationcontroller) that displays a view controller in a modal overlay style.
[Soli Deo gloria](https://perfectGod.com)
## Usage
```swift
extension SomeOtherViewController {
func presentPartialModalViewController() {
someNavigationController.modalPresentationStyle = .custom
someNavigationController.transitioningDelegate = someNavigationController.topViewController as? MyViewController
present(someNavigationController, animated: true, completion: nil)
}
}
extension MyViewController {
fileprivate var isMaximized: Bool {
if let controller = navigationController?.presentationController as? PartialModalPresentationController {
return controller.maximized
}
return false
}
@objc func toggleMaximizeButtonPressed(_ sender: AnyObject) {
guard let controller = navigationController?.presentationController as? PartialModalPresentationController else {
return
}
if isMaximized {
controller.unmaximizeViewController()
} else {
controller.maximizeViewController()
}
}
}
extension MyViewController: UIViewControllerTransitioningDelegate {
func presentationController(forPresented presented: UIViewController, presenting: UIViewController?, source: UIViewController) -> UIPresentationController? {
let ctrl = PartialModalPresentationController(presentedViewController: presented, presenting: presenting)
ctrl.presentationDelegate = self
ctrl.maximized = true
return ctrl
}
}
extension MyViewController: PartialModalPresentationDelegate {
func partialModalPresentationDimViewTapped(controller: PartialModalPresentationController) {
doneButtonPressed(self)
}
}
```