Overview
ResizableController is the custom model presentation style written in swift.
Features
Installation
This version is Swift 5 compatible.
CocoaPods
ResizableController is available through CocoaPods. To install
it, simply add the following line to your Podfile:
pod 'ResizableController', '~> 1.0'
Swift Package Manager
ResizableController is available through Swift Package Manager. To install
it, add package dependency from Url:
https://github.com/paytmmoney/ResizableController
Usage
ResizableControllerPositionHandler
View Controller to be presented, using resizable transition, needs to conform to protocol ResizableControllerPositionHandler
. This protocol inherits UIViewController at implementattion level.
public protocol ResizableControllerPositionHandler: UIViewController {
var shouldShowSlideUpIndication: Bool { get }
var sliderBackgroundColor: UIColor { get }
var initialTopOffset: CGFloat { get }
var finalTopOffset: CGFloat { get }
func willMoveTopOffset(value: CGFloat)
func didMoveTopOffset(value: CGFloat)
}
All the above properties are optional and can be added to achive different result.
shouldShowSlideUpIndication:
Override this property if you do not want to include intuitive slide up indicator. Disabled by default for non-resizable views controllers.
sliderBackgroundColor:
Override this property to give differnent colour to Slider up indicator. Defaults to darkGrey with alpha 0.5
initialTopOffset:
Override this property to give initial custom height, calculated from top.
Suggestion: Think about this offset as a topAnchor constraint we apply to a view.
finalTopOffset:
Override this property to give custom final height, calculated from top. Resizable controller will change its height from initialTopOffset to finalTopOffset.
willMoveTopOffset:
Override this property to add behaviours to view controller before it changes it size.
If you override this property, make sure you dismiss view controller manually as default behaviur will be overridden.
didMoveTopOffset:
Similar to willMoveTopOffset, but will trigger when animation is complete and view controller is resized.
Example
Rezisable View Controller
For creating a resizable controller. Conform to ResizableControllerPositionHandler
and override initialTopOffset
.
import ResizableController
class ResizablePresentedViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
}
}
extension ResizablePresentedViewController: ResizableControllerPositionHandler {
// This height 500 is from topAnchor
var initialTopOffset: CGFloat {
500
}
}
Fixed Height View Controller
For creating a fixed height controller. Conform to ResizableControllerPositionHandler
and override initialTopOffset
& finalTopOffset
.
import ResizableController
class FixedHeightPresentedViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
}
}
extension FixedHeightPresentedViewController: ResizableControllerPositionHandler {
// This height 500 is from topAnchor
var initialTopOffset: CGFloat {
500
}
// Both initial and final height should be same to make it a fixed height controller
var finalTopOffset: CGFloat {
500
}
}
or:
Do not override any property, this will give you iOS 13’s automatic presentation, which can be used with lower iOS versions.
import ResizableController
class FixedHeightPresentedViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
}
}
extension ResizablePresentedViewController: ResizableControllerPositionHandler {}
How to modally Present
To present, call this below overload method
func present(_ viewControllerToPresent: ResizableControllerPositionHandler,
animationDuration: TimeInterval = 0.3,
completion: (() -> Void)? = nil)
Example:
let viewController = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(identifier: "ResizablePresentedViewController") as ResizablePresentedViewController
self.present(viewController)
Author
Arjun Baru, iOS Engineer at Paytmoney Ltd, paytmmoney.com
You can reach out to me at arjun.baru@paytmmoney.com
In collaboration with:
Shahrukh Alam & Rahul Mathur
License
ResizableController is available under the MIT license. See the LICENSE file for more info.
Sample Project
Here is the sample project implementing ResizableController Sample Project
Suggestions or feedback?
Feel free to create a pull request, open an issue or find us on Twitter.
Overview
ResizableController is the custom model presentation style written in swift.
Features
Installation
This version is Swift 5 compatible.
CocoaPods
ResizableController is available through CocoaPods. To install it, simply add the following line to your Podfile:
Swift Package Manager
ResizableController is available through Swift Package Manager. To install it, add package dependency from Url:
Usage
ResizableControllerPositionHandler
View Controller to be presented, using resizable transition, needs to conform to protocol
ResizableControllerPositionHandler
. This protocol inherits UIViewController at implementattion level.All the above properties are optional and can be added to achive different result.
shouldShowSlideUpIndication:
Override this property if you do not want to include intuitive slide up indicator. Disabled by default for non-resizable views controllers.
sliderBackgroundColor:
Override this property to give differnent colour to Slider up indicator. Defaults to darkGrey with alpha 0.5
initialTopOffset:
Override this property to give initial custom height, calculated from top.
Suggestion: Think about this offset as a topAnchor constraint we apply to a view.
finalTopOffset:
Override this property to give custom final height, calculated from top. Resizable controller will change its height from initialTopOffset to finalTopOffset.
willMoveTopOffset:
Override this property to add behaviours to view controller before it changes it size. If you override this property, make sure you dismiss view controller manually as default behaviur will be overridden.
didMoveTopOffset:
Similar to willMoveTopOffset, but will trigger when animation is complete and view controller is resized.
Example
Rezisable View Controller
For creating a resizable controller. Conform to
ResizableControllerPositionHandler
and overrideinitialTopOffset
.Fixed Height View Controller
For creating a fixed height controller. Conform to
ResizableControllerPositionHandler
and overrideinitialTopOffset
&finalTopOffset
.or:
Do not override any property, this will give you iOS 13’s automatic presentation, which can be used with lower iOS versions.
How to modally Present
To present, call this below overload method
Example:
Author
Arjun Baru, iOS Engineer at Paytmoney Ltd, paytmmoney.com
You can reach out to me at arjun.baru@paytmmoney.com
In collaboration with:
Shahrukh Alam & Rahul Mathur
License
ResizableController is available under the MIT license. See the LICENSE file for more info.
Sample Project
Here is the sample project implementing ResizableController Sample Project
Suggestions or feedback?
Feel free to create a pull request, open an issue or find us on Twitter.