-
Notifications
You must be signed in to change notification settings - Fork 317
/
Copy pathViewController.swift
78 lines (63 loc) · 2.89 KB
/
ViewController.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
//
// Copyright © 2014 Yalantis
// Licensed under the MIT license: http://opensource.org/licenses/MIT
// Latest version can be found at http://github.com/yalantis/Side-Menu.iOS
//
import UIKit
import SideMenu
class ViewController: UIViewController {
fileprivate var selectedIndex = 0
fileprivate var transitionPoint: CGPoint!
fileprivate var contentType: ContentType = .Music
fileprivate var navigator: UINavigationController!
lazy fileprivate var menuAnimator : MenuTransitionAnimator! = MenuTransitionAnimator(mode: .presentation, shouldPassEventsOutsideMenu: false) { [unowned self] in
self.dismiss(animated: true, completion: nil)
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
switch (segue.identifier, segue.destination) {
case (.some("presentMenu"), let menu as MenuViewController):
menu.selectedItem = selectedIndex
menu.delegate = self
menu.transitioningDelegate = self
menu.modalPresentationStyle = .custom
case (.some("embedNavigator"), let navigator as UINavigationController):
self.navigator = navigator
self.navigator.delegate = self
default:
super.prepare(for: segue, sender: sender)
}
}
}
extension ViewController: MenuViewControllerDelegate {
func menu(_: MenuViewController, didSelectItemAt index: Int, at point: CGPoint) {
contentType = !contentType
transitionPoint = point
selectedIndex = index
let content = storyboard!.instantiateViewController(withIdentifier: "Content") as! ContentViewController
content.type = contentType
navigator.setViewControllers([content], animated: true)
DispatchQueue.main.async {
self.dismiss(animated: true, completion: nil)
}
}
func menuDidCancel(_: MenuViewController) {
dismiss(animated: true, completion: nil)
}
}
extension ViewController: UINavigationControllerDelegate {
public func navigationController(_ navigationController: UINavigationController, animationControllerFor operation: UINavigationController.Operation, from fromVC: UIViewController, to toVC: UIViewController) -> UIViewControllerAnimatedTransitioning? {
if let transitionPoint = transitionPoint {
return CircularRevealTransitionAnimator(center: transitionPoint)
}
return nil
}
}
extension ViewController: UIViewControllerTransitioningDelegate {
func animationController(forPresented presented: UIViewController, presenting _: UIViewController,
source _: UIViewController) -> UIViewControllerAnimatedTransitioning? {
return menuAnimator
}
func animationController(forDismissed dismissed: UIViewController) -> UIViewControllerAnimatedTransitioning? {
return MenuTransitionAnimator(mode: .dismissal)
}
}