-
Notifications
You must be signed in to change notification settings - Fork 44
/
DrawerDisplayController+Extensions.swift
executable file
·63 lines (57 loc) · 3.47 KB
/
DrawerDisplayController+Extensions.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
import UIKit
extension DrawerDisplayController: UIViewControllerTransitioningDelegate {
public func presentationController(forPresented presented: UIViewController,
presenting: UIViewController?,
source: UIViewController) -> UIPresentationController? {
let presentationController = PresentationController(presentingVC: presentingVC,
presentedVC: presented,
configuration: configuration,
inDebugMode: inDebugMode)
presentationController.delegate = self
return presentationController
}
public func animationController(forPresented presented: UIViewController,
presenting: UIViewController,
source: UIViewController) -> UIViewControllerAnimatedTransitioning? {
return AnimationController(isPresentation: true,
durationInSeconds: durationInSeconds,
timingCurveProvider: timingCurveProvider)
}
public func animationController(forDismissed dismissed: UIViewController) -> UIViewControllerAnimatedTransitioning? {
return AnimationController(isPresentation: false,
durationInSeconds: durationInSeconds,
timingCurveProvider: timingCurveProvider)
}
public func interactionControllerForPresentation(using animator: UIViewControllerAnimatedTransitioning) -> UIViewControllerInteractiveTransitioning? {
if #available(iOS 11.0, *) {
guard isDrawerDraggable else { return nil }
return InteractionController(isPresentation: true,
presentingVC: presentingVC!,
presentedVC: presentedVC)
} else {
// On iOS 10, there seems to be a bug in UIKit that causes the interactive animation
// not to complete under the conditions we have here, in which case viewDidAppear
// doesn't get called and the drawer isn't visible. An easy work-around is to return
// nil here, but that means the initial presentation and dismissal aren't going to
// be interactive.
return nil
}
}
public func interactionControllerForDismissal(using animator: UIViewControllerAnimatedTransitioning) -> UIViewControllerInteractiveTransitioning? {
if #available(iOS 11.0, *) {
guard isDrawerDraggable else { return nil }
return InteractionController(isPresentation: false,
presentingVC: presentingVC!,
presentedVC: presentedVC)
} else {
// On iOS 10, there seems to be a bug in UIKit that causes the interactive animation
// not to complete under the conditions we have here, in which case viewDidAppear
// doesn't get called and the drawer isn't visible. An easy work-around is to return
// nil here, but that means the initial presentation and dismissal aren't going to
// be interactive.
return nil
}
}
}
// TODO: Implement support for adaptive presentations.
extension DrawerDisplayController: UIAdaptivePresentationControllerDelegate {}