-
Notifications
You must be signed in to change notification settings - Fork 1
/
ConcentrationThemeViewController.swift
73 lines (56 loc) · 2.48 KB
/
ConcentrationThemeViewController.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
//
// ConcentrationThemeViewController.swift
// Concentration
//
// Created by BHAVANASINGH on 28/01/19.
// Copyright © 2019 Stanford University. All rights reserved.
//
import UIKit
class ConcentrationThemeViewController: UIViewController, UISplitViewControllerDelegate {
let themes = [
"Animals":"🐶🐣🐼🐙🦋🐳🐯🦁🐨🐝",
"Sports":"⚽️🏀🏈⚾️🎾🏐🏓🏑🥊⛳️",
"Halloween":"🦇😱🙀😈🎃👻💀🧛♂️👾☠️",]
// MARK: - Navigation
override func awakeFromNib() {
splitViewController?.delegate = self
}
//Function for iphone home screen THEME display.
func splitViewController(_ splitViewController: UISplitViewController, collapseSecondary secondaryViewController: UIViewController, onto primaryViewController: UIViewController) -> Bool {
//Fuction asking : did you do it?
if let cvc = secondaryViewController as? ConcentrationViewController {
if cvc.theme == nil {
return true
}
}
return false
}
@IBAction func chooseTheme(_ sender: Any) {
if let cvc = splitViewDetailViewController {
if let themeName = (sender as? UIButton)?.currentTitle, let theme = themes[themeName]{
cvc.theme = theme
}
}else if let cvc = lastSeguedToConcentrationViewController {
if let themeName = (sender as? UIButton)?.currentTitle, let theme = themes[themeName]{
cvc.theme = theme
}
navigationController?.pushViewController(cvc,animated: true)
}else {
performSegue(withIdentifier: "Choose Theme" , sender: sender)
}
}
private var splitViewDetailViewController : ConcentrationViewController?{
return splitViewController?.viewControllers.last as? ConcentrationViewController
}
var lastSeguedToConcentrationViewController: ConcentrationViewController?
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "Choose Theme" {
if let themeName = (sender as? UIButton)?.currentTitle, let theme = themes[themeName]{
if let cvc = segue.destination as? ConcentrationViewController {
cvc.theme = theme
lastSeguedToConcentrationViewController = cvc
}
}
}
}
}