-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathDailyViewController.swift
213 lines (185 loc) · 8.48 KB
/
DailyViewController.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
//
// TableViewController.swift
// Sfest-swift
//
// Created by Peter Zignego on 6/23/14.
// Copyright (c) 2014 Launch Software. All rights reserved.
import UIKit
protocol DateChangedDelegate {
func dateChanged(stage:String, date:String)
}
class DailyViewController: UIViewController, UIGestureRecognizerDelegate {
@IBOutlet var stageView: UIView!
@IBOutlet var stageNameLabel: UILabel!
@IBOutlet var dateView: UIView!
@IBOutlet var dayOfTheWeekLabel: UILabel!
@IBOutlet var dateLabel: UILabel!
@IBOutlet var closeButton: UIButton!
var backgroundImage: UIImage?
var returnRectangle: CGRect?
var savedScrollPosition: CGPoint?
var selectedIndex: NSIndexPath?
var stageName: String?
var stageColor: UIColor?
var globalDate : NSDate?
var delegate: DateChangedDelegate?
var tableViewController: TableViewController?
var mapView: MapView?
override func viewDidLoad() {
super.viewDidLoad()
globalDate = dateTest(NSDate())
setupViews()
gestureRecognizers()
tableViewController = childViewControllers[0] as? TableViewController
self.delegate = tableViewController
delegate?.dateChanged(stageName!, date: convertDateToStrings(globalDate!).queryDateString)
}
override func viewDidAppear(animated: Bool) {
let animateView = UIView(frame:CGRect(x: 0, y: 45, width: UIScreen.mainScreen().bounds.size.width, height: UIScreen.mainScreen().bounds.size.height-45))
animateView.backgroundColor = stageColor
view.addSubview(animateView)
UIView.animateWithDuration(0.5, delay: 0.00, usingSpringWithDamping: 0.5, initialSpringVelocity: 1.00, options: UIViewAnimationOptions.CurveEaseOut, animations:{
animateView.frame = CGRect(x: 0.0, y: UIScreen.mainScreen().bounds.size.height, width: UIScreen.mainScreen().bounds.size.width, height:UIScreen.mainScreen().bounds.size.height-45)
}, completion: {
finished in
animateView.removeFromSuperview()
})
}
override func preferredStatusBarStyle() -> UIStatusBarStyle {
return UIStatusBarStyle.LightContent
}
func setupViews() {
//Stage
stageView.backgroundColor = stageColor
stageNameLabel.text = stageName
//Date
dayOfTheWeekLabel!.text = convertDateToStrings(globalDate!).dayOfTheWeek
dateLabel!.text = convertDateToStrings(globalDate!).longDateString
dateView.backgroundColor = NSUserDefaults.standardUserDefaults().colorForKey("complimentaryColor")
//Close Button
view.bringSubviewToFront(closeButton)
}
func gestureRecognizers() {
let pinchGesture = UIPinchGestureRecognizer(target: self, action: "pinchToClose:")
let swipeLeftGesture = UISwipeGestureRecognizer(target: self, action: "dateForward:")
swipeLeftGesture.direction = UISwipeGestureRecognizerDirection.Left
let swipeRightGesture = UISwipeGestureRecognizer(target: self, action: "dateBackward:")
swipeRightGesture.direction = UISwipeGestureRecognizerDirection.Right
view.addGestureRecognizer(pinchGesture)
view.addGestureRecognizer(swipeLeftGesture)
view.addGestureRecognizer(swipeRightGesture)
}
func close() {
if (mapView?.frame.origin.y == 45) {
hideMapView(closeButton)
}
else {
popToStageViewController()
}
}
@IBAction func buttonToClose(sender: UIButton) {
close()
}
func pinchToClose(sender:UIPinchGestureRecognizer) {
close()
}
func popToStageViewController() {
let backgroundImageView:UIImageView = UIImageView(image: backgroundImage!)
view.addSubview(backgroundImageView)
let animateView = UIView(frame: CGRect(x: 0, y: 0, width: UIScreen.mainScreen().bounds.size.width, height: UIScreen.mainScreen().bounds.size.height))
animateView.backgroundColor = stageColor
view.addSubview(animateView)
UIView.animateWithDuration(0.5, animations: {
animateView.frame = self.returnRectangle!
animateView.alpha = 0.5
}, completion: {
finished in
animateView.removeFromSuperview()
backgroundImageView.removeFromSuperview()
let stageViewController = self.navigationController!.viewControllers[0] as! StageViewController
stageViewController.savedScrollPosition = self.savedScrollPosition!
self.navigationController!.popToRootViewControllerAnimated(false)
})
}
func dateTest(aDate:NSDate) -> NSDate {
let dateComponents = NSDateComponents()
dateComponents.calendar = NSCalendar.currentCalendar()
dateComponents.year = 2013
dateComponents.month = 6
dateComponents.day = 26
let startDate = dateComponents.date
dateComponents.year = 2013
dateComponents.month = 7
dateComponents.day = 7
let endDate = dateComponents.date
let startDateComparisonResult = aDate.compare(startDate!)
let endDateComparisonResult = aDate.compare(endDate!)
if (startDateComparisonResult == NSComparisonResult.OrderedAscending){
return startDate!
}
else if (endDateComparisonResult == NSComparisonResult.OrderedDescending){
return endDate!
}
else {
return aDate
}
}
@IBAction func dateForwardButton(sender: UIButton) {
dateForward(sender)
}
func dateForward(sender:UIButton) {
globalDate = dateTest(globalDate!.dateByAddingTimeInterval(24*60*60))
dayOfTheWeekLabel!.text = convertDateToStrings(globalDate!).dayOfTheWeek
dateLabel!.text = convertDateToStrings(globalDate!).longDateString
delegate?.dateChanged(stageName!, date: convertDateToStrings(globalDate!).queryDateString)
}
@IBAction func dateBackwardButton(sender: UIButton) {
dateBackward(sender)
}
func dateBackward(sender:UIButton) {
globalDate = dateTest(globalDate!.dateByAddingTimeInterval(-24*60*60))
dayOfTheWeekLabel!.text = convertDateToStrings(globalDate!).dayOfTheWeek
dateLabel!.text = convertDateToStrings(globalDate!).longDateString
delegate?.dateChanged(stageName!, date: convertDateToStrings(globalDate!).queryDateString)
}
func convertDateToStrings(date:NSDate) -> (queryDateString:String, longDateString:String, dayOfTheWeek:String) {
let dateFormatter = NSDateFormatter()
dateFormatter.dateFormat = "M/d/yyyy"
let queryString = dateFormatter.stringFromDate(date)
dateFormatter.dateStyle = NSDateFormatterStyle.LongStyle
let longString = dateFormatter.stringFromDate(date)
dateFormatter.dateFormat = "EEEE"
let dayString = dateFormatter.stringFromDate(date)
return (queryString, longString, dayString)
}
@IBAction func mapViewButton(sender: UIButton) {
if (mapView?.frame.origin.y == 45) {
hideMapView(sender)
}
else {
showMapView(sender)
}
}
func showMapView(sender:UIButton) {
mapView = MapView(stage: stageName!)
self.view.addSubview(mapView!)
view.bringSubviewToFront(closeButton)
mapView!.frame = CGRect(x: 0, y: UIScreen.mainScreen().bounds.size.height, width: UIScreen.mainScreen().bounds.size.width, height: UIScreen.mainScreen().bounds.size.height-45)
UIView.animateWithDuration(0.5, delay: 0.00, usingSpringWithDamping: 0.5, initialSpringVelocity: 1.00, options: UIViewAnimationOptions.CurveEaseOut, animations:{
self.mapView!.frame = CGRect(x: 0, y: 45, width: UIScreen.mainScreen().bounds.size.width, height: UIScreen.mainScreen().bounds.size.height-45)
}, completion: {
finished in
})
}
func hideMapView(sender:UIButton) {
UIView.animateWithDuration(0.5, delay: 0.00, usingSpringWithDamping: 0.5, initialSpringVelocity: 1.00, options: UIViewAnimationOptions.CurveEaseOut, animations:{
self.mapView!.frame = CGRect(x: 0, y: UIScreen.mainScreen().bounds.size.height, width: UIScreen.mainScreen().bounds.size.width, height: UIScreen.mainScreen().bounds.size.height-45)
}, completion: {
finished in
self.mapView?.removeFromSuperview()
self.mapView = nil
})
}
override func didReceiveMemoryWarning() {
}
}