-
Notifications
You must be signed in to change notification settings - Fork 44
/
PresenterViewController.swift
80 lines (68 loc) · 4.02 KB
/
PresenterViewController.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import UIKit
import DrawerKit
class PresenterViewController: UIViewController, DrawerCoordinating {
/* strong */ var drawerDisplayController: DrawerDisplayController?
@IBAction func presentButtonTapped() {
doModalPresentation(passthrough: false)
}
@IBAction func presentButtonDoubleTapped() {
doModalPresentation(passthrough: true)
}
@IBAction func alertButtonTapped() {
let alert = UIAlertController(title: "Alert", message: "", preferredStyle: .alert)
alert.addAction(UIAlertAction.init(title: "OK", style: .default, handler: nil))
(self.presentedViewController ?? self).present(alert, animated: true, completion: nil)
}
}
private extension PresenterViewController {
func doModalPresentation(passthrough: Bool) {
guard let vc = storyboard?.instantiateViewController(withIdentifier: "presented")
as? PresentedNavigationController else { return }
// you can provide the configuration values in the initialiser...
var configuration = DrawerConfiguration(/* ..., ..., ..., */)
// ... or after initialisation. All of these have default values so change only
// what you need to configure differently. They're all listed here just so you
// can see what can be configured. The values listed are the default ones,
// except where indicated otherwise.
// configuration.initialState = .collapsed
configuration.totalDurationInSeconds = 0.4
configuration.durationIsProportionalToDistanceTraveled = false
// default is UISpringTimingParameters()
configuration.timingCurveProvider = UISpringTimingParameters(dampingRatio: 0.8)
configuration.fullExpansionBehaviour = .coversFullScreen
configuration.supportsPartialExpansion = true
configuration.dismissesInStages = true
configuration.isDrawerDraggable = true
configuration.isFullyPresentableByDrawerTaps = true
configuration.numberOfTapsForFullDrawerPresentation = 1
configuration.isDismissableByOutsideDrawerTaps = true
configuration.numberOfTapsForOutsideDrawerDismissal = 1
configuration.flickSpeedThreshold = 3
configuration.upperMarkGap = 100 // default is 40
configuration.lowerMarkGap = 80 // default is 40
configuration.maximumCornerRadius = 15
configuration.cornerAnimationOption = .none
configuration.passthroughTouchesInStates = passthrough ? [.collapsed, .partiallyExpanded] : []
var handleViewConfiguration = HandleViewConfiguration()
handleViewConfiguration.autoAnimatesDimming = true
handleViewConfiguration.backgroundColor = .gray
handleViewConfiguration.size = CGSize(width: 40, height: 6)
handleViewConfiguration.top = 8
handleViewConfiguration.cornerRadius = .automatic
configuration.handleViewConfiguration = handleViewConfiguration
let borderColor = UIColor(red: 1, green: 0, blue: 0, alpha: 1)
let drawerBorderConfiguration = DrawerBorderConfiguration(borderThickness: 0.5,
borderColor: borderColor)
configuration.drawerBorderConfiguration = drawerBorderConfiguration // default is nil
let drawerShadowConfiguration = DrawerShadowConfiguration(shadowOpacity: 0.75,
shadowRadius: 10,
shadowOffset: .zero,
shadowColor: .red)
configuration.drawerShadowConfiguration = drawerShadowConfiguration // default is nil
drawerDisplayController = DrawerDisplayController(presentingViewController: self,
presentedViewController: vc,
configuration: configuration,
inDebugMode: true)
present(vc, animated: true)
}
}