DYModalNavigationController is a simple UINavigationController subclass written in Swift 5.0. Use cases:
- present a small size view controller with rounded edges over the current context modally (e.g. if the content is rather small and the standard modal presentation would show a lot of empty space). Set a fixed size so that the navigation controller's size is not adjusted when the screen orientation changes.
- present a modal view controller over the current context with top, bottom, left, right margins with a fade in transition. The presenting view controller behind it is still visible at the margins (unless margins set to 0). The size adjusts automatically when the screen orientation changes.
- works in a SwiftUI project even without using UIViewControllerRepresentable. Simply create an instance of the DYModalNavigationController and call present() on the instance (available from version 1.2.1)
To checkout the example project, simply clone the repo or download the zip file.
- Create a DYModalNavigationController with a fixed size in case your view controller instance should not change its size when changing the screen orientation.
- Set a background blur or dim effect
- Customise the corner radius of the DYModalNavigationController view.
- Set a slide in/out animation (customisable animation movement directions) or a fade in/out animation
- Customise the drop shadow
- Customise the animation transition duration
Installation through Cocoapods or Carthage is recommended.
Cocoapods:
target '[project name]' do pod 'DYModalNavigationController' end
Carthage: Simply add the following line to your Cartfile.
github "DominikButz/DYModalNavigationController" ~> 1.0
Check out the version history below for the current version.
Afterwards, run "carthage update DYModalNavigationController --platform iOS" in the root directory of your project. Follow the steps described in the carthage project on github (click on the carthage compatible shield above).
Make sure to import DYModalNavigationController into your View Controller subclass:
import DYModalNavigationController
Check out the following examples.
let size = CGSize(width: 300, height: 200)
var settings = DYModalNavigationControllerSettings()
settings.slideInDirection = .right
settings.slideOutDirection = .right
settings.backgroundEffect = .blur
self.navController = DYModalNavigationController(rootViewController: contentVC(), fixedSize: size, settings: settings)
var settings = DYModalNavigationControllerSettings()
settings.animationType = .fadeInOut
// animationType .slideInOut is default setting!
self.navController = DYModalNavigationController(rootViewController: contentVC(), fixedSize: nil, settings: settings)
// with fixedSize nil, the size will be set according to the top, bottom, left, right margins in the settings.
var settings = DYModalNavigationControllerSettings()
settings.animationType = .custom
self.navController = DYModalNavigationController(rootViewController: contentVC(), fixedSize: size, settings: settings, customPresentationAnimation: { (transitionContext) in
self.foldOut(transitionContext: transitionContext, navController: self.navController)
}, customDismissalAnimation: { (transitionContext) in
self.foldIn(transitionContext: transitionContext, navController: self.navController)
})
bottom margin bug fix
The nav controller is not bound to the bottom anchor of the container view when presenting. the constraint only works if the nav controller has a fixed size and enters the screen from the top or bottom. This change prevents a gap on devices with large safe area at the bottom of the screen (like iPhone 11 etc.).
Added customMask as property in DYModalNavigationControllerSettings (allows rounding a subset of corners). Added extension for SwiftUI with present function.
added backgroundEffectView as accessible parameter in the customAnimation closures.
added customPresentationAnimation and customDismissalAnimation to the initializer.
initial version.
DYModalNavigationController is available under the MIT license. See the LICENSE file for more info.