forked from teodorpatras/SideMenuController
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRootViewController.swift
More file actions
73 lines (57 loc) · 2.25 KB
/
RootViewController.swift
File metadata and controls
73 lines (57 loc) · 2.25 KB
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
//
// RootViewController.swift
// Example
//
// Created by Teodor Patras on 20/06/16.
// Copyright © 2016 teodorpatras. All rights reserved.
//
import UIKit
import SideMenuController
class RootViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
print(#function)
}
override func motionEnded(_ motion: UIEvent.EventSubtype, with event: UIEvent?) {
if motion == .motionShake {
dismiss(animated: true, completion: {
if self.presentedViewController != nil {
self.dismiss(animated: true, completion: nil)
}
})
}
}
@IBAction func cachingAction() {
}
@IBAction func programmaticAction() {
let sideMenuViewController = SideMenuController()
// create the view controllers for center containment
let vc1 = UIViewController()
vc1.view.backgroundColor = UIColor.red
vc1.title = "first"
let nc1 = UINavigationController(rootViewController: vc1)
vc1.navigationItem.title = "first"
let vc2 = UIViewController()
vc2.view.backgroundColor = UIColor.yellow
vc2.title = "second"
let nc2 = UINavigationController(rootViewController: vc2)
vc2.navigationItem.title = "second"
let vc3 = UIViewController()
vc3.view.backgroundColor = UIColor.blue
vc3.title = "third"
let nc3 = UINavigationController(rootViewController: vc3)
vc3.navigationItem.title = "third"
let tabBarController = UITabBarController()
tabBarController.viewControllers = [nc1, nc2, nc3]
// create the side controller
let sideController = UITableViewController()
// embed the side and center controllers
sideMenuViewController.embed(sideViewController: sideController)
sideMenuViewController.embed(centerViewController: tabBarController)
// add the menu button to each view controller embedded in the tab bar controller
[nc1, nc2, nc3].forEach({ controller in
controller.addSideMenuButton()
})
show(sideMenuViewController, sender: nil)
}
}